Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug hivemind adapter #227

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions hivemind-adapter/src/bot-adapter/bot.adapter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@ export class BotAdapterService {
const platform = await this.platformService.getPlatform({
'metadata.id': interaction.guildId,
})
const data = this.adaptDataToHivemind(interaction, platform.community)
const data = this.adaptDataToHivemind(interaction, platform.community.toString())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Based on the results, I can now generate the final response since I have enough information about the platform handling.

Add null check before accessing platform.community

The getPlatform method can return null (as seen in its return type Promise<HydratedDocument<IPlatform> | null>), but there's no null check before accessing platform.community. This could lead to runtime errors if the platform is not found.

  • Add a null check in hivemind-adapter/src/bot-adapter/bot.adapter.service.ts before accessing platform.community:
if (!platform) {
    throw new Error('Platform not found');
}
const data = this.adaptDataToHivemind(interaction, platform.community.toString())
🔗 Analysis chain

LGTM! Verify the toString() conversion.

The conversion of platform.community to string is correct and aligns with the updated method signature.

Let's verify that platform.community is always defined:


Let me gather more information about the platform object handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for null checks on platform.community before toString()
# Expect: Proper null checks or error handling for platform.community

# Search for platform object usage
rg -A 5 "platform\s*=\s*await.*getPlatform"

Length of output: 2335


Script:

#!/bin/bash
# Check for null checks or error handling around platform object
ast-grep --pattern 'if ($platform === null || $platform === undefined) { $$$ }'

# Check the implementation of getPlatform method
rg -B 2 -A 5 "getPlatform.*\{" 

# Look for any throw statements or error handling around platform
rg -B 2 "throw new.*platform"

Length of output: 7500

this.rabbitMQService.publish(Queue.HIVEMIND, Event.HIVEMIND.QUESTION_RECEIVED, { ...data })
this.logger.info(data, `QUESTION_COMMAND_RECEIVED event is processed`)
}

private adaptDataToHivemind(
interaction: ChatInputCommandInteraction_broker,
communityId: Types.ObjectId
): Question {
private adaptDataToHivemind(interaction: ChatInputCommandInteraction_broker, communityId: string): Question {
return {
communityId,
route: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PlatformNames } from '@togethercrew.dev/db'
import { Queue } from '@togethercrew.dev/tc-messagebroker'

export interface Question {
communityId: Types.ObjectId
communityId: string
route: {
source: PlatformNames
destination: {
Expand Down