fix(core): Prevent crash in cleanMessageData on null message#2159
Closed
moothz wants to merge 1 commit intoEvolutionAPI:developfrom
Closed
fix(core): Prevent crash in cleanMessageData on null message#2159moothz wants to merge 1 commit intoEvolutionAPI:developfrom
moothz wants to merge 1 commit intoEvolutionAPI:developfrom
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.
Contributor
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
|
Contributor
There was a problem hiding this comment.
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; |
Contributor
There was a problem hiding this comment.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)
Suggested change
| 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
Contributor
Author
|
Vi agora no discord que falaram que já está feito esse fix, não sendo necessário meu PR. Criei um novo na /develop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 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: