-
Notifications
You must be signed in to change notification settings - Fork 5.2k
fix(core): Prevent crash in cleanMessageData on null message #2159
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
fix(core): Prevent crash in cleanMessageData on null message #2159
Conversation
Modificação simples que previne erros de acesso à propriedades não definidas de objetos, que interrompem o fluxo do /chat/findChats e fazem com o que os chats no manager não sejam carregados.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideIntroduce null checks in cleanMessageData to prevent property-access crashes and correctly maintain mediaUrl during message cleaning by restructuring the extraction and restoration steps within the message existence guard. Sequence diagram for cleanMessageData null-safe message cleaningsequenceDiagram
participant S as "ChannelStartupService"
participant M as "message (input)"
participant C as "cleanedMessage (output)"
S->>M: Receives message
alt message exists
S->>M: Extract mediaUrl
S->>M: Delete base64
S->>M: Clean imageMessage
S->>M: Clean documentWithCaptionMessage
S->>M: Restore mediaUrl if present
else message is null
S->>C: Return cleanedMessage unchanged
end
Class diagram for updated ChannelStartupService.cleanMessageDataclassDiagram
class ChannelStartupService {
+cleanMessageData(message)
}
class Message {
mediaUrl
base64
imageMessage
documentWithCaptionMessage
}
class ImageMessage {
caption
mimetype
name
}
class DocumentWithCaptionMessage {
caption
mimetype
name
}
ChannelStartupService --> Message
Message --> ImageMessage
Message --> DocumentWithCaptionMessage
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Consider doing an early return when
cleanedMessage.messageis falsy to avoid deep nesting and make the intent clearer. - You could simplify the null checks with optional chaining (e.g.
cleanedMessage.message?.mediaUrl) to reduce mutable assignments and improve readability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider doing an early return when `cleanedMessage.message` is falsy to avoid deep nesting and make the intent clearer.
- You could simplify the null checks with optional chaining (e.g. `cleanedMessage.message?.mediaUrl`) to reduce mutable assignments and improve readability.
## Individual Comments
### Comment 1
<location> `src/api/services/channel.service.ts:539` </location>
<code_context>
const mediaUrl = cleanedMessage.message.mediaUrl;
</code_context>
<issue_to_address>
**suggestion (code-quality):** Prefer object destructuring when accessing and using properties. ([`use-object-destructuring`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/TypeScript/Default-Rules/use-object-destructuring))
```suggestion
const {mediaUrl} = cleanedMessage.message;
```
<br/><details><summary>Explanation</summary>Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.
From the [Airbnb Javascript Style Guide](https://airbnb.io/javascript/#destructuring--object)
</details>
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| delete cleanedMessage.message.base64; | ||
|
|
||
| if (cleanedMessage.message) { | ||
| const mediaUrl = cleanedMessage.message.mediaUrl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)
| const mediaUrl = cleanedMessage.message.mediaUrl; | |
| const {mediaUrl} = cleanedMessage.message; |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
|
Vi agora no discord que falaram que já está feito esse fix, não sendo necessário meu PR. Criei um novo na /develop |
📋 Description
Modificação simples que previne erros de acesso à propriedades não definidas de objetos, que interrompem o fluxo do /chat/findChats e fazem com o que os chats no manager não sejam carregados.
Resolve esses erros:
🔗 Related Issue
Closes #2058
🧪 Type of Change
🧪 Testing
✅ Checklist
Summary by Sourcery
Bug Fixes: