Skip to content

Meshbir parsing#378

Merged
vicb merged 1 commit into
masterfrom
vicb/meshbir
Oct 26, 2025
Merged

Meshbir parsing#378
vicb merged 1 commit into
masterfrom
vicb/meshbir

Conversation

@vicb
Copy link
Copy Markdown
Owner

@vicb vicb commented Oct 26, 2025

Summary by Sourcery

Improve meshbir message parsing and correct test typo

Bug Fixes:

  • Fix typo in parseMessage test by changing 'unkown' to 'unknown'

Enhancements:

  • Add try-catch around JSON.parse in flushMessageQueue to log and filter out malformed messages

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced message queue processing to gracefully handle and log malformed entries instead of crashing the system.
  • Tests

    • Corrected typo in test case.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Oct 26, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR enhances the robustness of MeshBir message parsing by adding error handling and filtering for malformed JSON in flushMessageQueue, and corrects a typo in the meshbir route tests to ensure invalid message type is validated properly.

Class diagram for updated MeshBir message parsing in flushMessageQueue

classDiagram
class flushMessageQueue {
  +Promise<MeshBirMessage[]> flushMessageQueue(redis: Redis)
}
class MeshBirMessage
flushMessageQueue --> MeshBirMessage: returns array of

flushMessageQueue : +try/catch JSON.parse
flushMessageQueue : +console.error on parse failure
flushMessageQueue : +filters out undefined messages
Loading

Flow diagram for enhanced error handling in flushMessageQueue

flowchart TD
    A["Retrieve messages from Redis"] --> B["Iterate over messages"]
    B --> C["Try to parse JSON"]
    C -->|Success| D["Add to result array"]
    C -->|Failure| E["Log error and skip message"]
    D & E --> F["Filter out undefined messages"]
    F --> G["Sort messages by time"]
    G --> H["Return sorted array"]
Loading

File-Level Changes

Change Details Files
Add resilient JSON parsing for meshbir message queue
  • Wrapped JSON.parse in a try-catch block
  • Logged parsing errors with console.error
  • Returned undefined on parse failure
  • Filtered out undefined messages before sorting
apps/fetcher/src/app/trackers/meshbir.ts
Fix typo in invalid message type test
  • Changed 'unkown' to 'unknown' in test input
  • Updated the error assertion to match corrected type
apps/fxc-server/src/app/routes/meshbir.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 26, 2025

Walkthrough

This pull request adds robust JSON parsing error handling to the meshbir queue processing by wrapping JSON.parse in a try-catch block, logging parsing errors, and filtering out malformed entries to prevent crashes during queue processing.

Changes

Cohort / File(s) Summary
Error handling for JSON parsing
apps/fetcher/src/app/trackers/meshbir.ts
Wraps JSON.parse in try-catch, logs parsing errors, and filters out malformed JSON entries from queue items instead of crashing on invalid data
Test typo fix
apps/fxc-server/src/app/routes/meshbir.test.ts
Corrects typo in type value from 'unkown' to 'unknown' in invalid message test assertion

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

  • Primary focus: verify that silently filtering malformed queue entries (with logging) is the desired behavior
  • Check that error logging is adequate for debugging queue issues
  • Confirm test typo fix is isolated and correct

Possibly related PRs

Poem

🐰 A JSON parse that once would fall,
Now caught with grace, it won't crash at all—
Malformed entries logged then filtered away,
The queue flows steady, day after day! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Meshbir parsing" is directly related to the main change in the changeset, which adds robust error handling for JSON parsing in the meshbir queue message processing. The title is concise, clear, and specific enough that a teammate scanning the commit history would understand it pertains to meshbir parsing improvements. While the title is somewhat brief and doesn't explicitly mention error handling or robustness, it accurately captures the primary focus of the changes without being misleading or overly vague. The secondary change (typo fix in a test) is appropriately not highlighted in the title since it's a minor supporting change.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch vicb/meshbir

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a 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 and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `apps/fetcher/src/app/trackers/meshbir.ts:159-166` </location>
<code_context>
     // Return older messages first
     return (messages as string[])
-      .map((json) => JSON.parse(json) as MeshBirMessage)
+      .map((json) => {
+        try {
+          return JSON.parse(json) as MeshBirMessage;
+        } catch {
+          console.error(`Error parsing meshbir ${json}`);
+          return undefined;
+        }
+      })
</code_context>

<issue_to_address>
**suggestion:** Consider logging the error object for more context when JSON.parse fails.

Logging the error object alongside the JSON string will make it easier to identify the cause of parsing failures.

```suggestion
      .map((json) => {
        try {
          return JSON.parse(json) as MeshBirMessage;
        } catch (err) {
          console.error(`Error parsing meshbir ${json}`, err);
          return undefined;
        }
      })
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +159 to +166
.map((json) => {
try {
return JSON.parse(json) as MeshBirMessage;
} catch {
console.error(`Error parsing meshbir ${json}`);
return undefined;
}
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider logging the error object for more context when JSON.parse fails.

Logging the error object alongside the JSON string will make it easier to identify the cause of parsing failures.

Suggested change
.map((json) => {
try {
return JSON.parse(json) as MeshBirMessage;
} catch {
console.error(`Error parsing meshbir ${json}`);
return undefined;
}
})
.map((json) => {
try {
return JSON.parse(json) as MeshBirMessage;
} catch (err) {
console.error(`Error parsing meshbir ${json}`, err);
return undefined;
}
})

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0633d6b and ed22388.

📒 Files selected for processing (2)
  • apps/fetcher/src/app/trackers/meshbir.ts (1 hunks)
  • apps/fxc-server/src/app/routes/meshbir.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
apps/fxc-server/src/app/routes/meshbir.test.ts (1)
apps/fxc-server/src/app/routes/meshbir.ts (1)
  • parseMessage (46-55)
apps/fetcher/src/app/trackers/meshbir.ts (1)
libs/common-node/src/lib/meshtbir.ts (1)
  • MeshBirMessage (31-31)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Sourcery review
  • GitHub Check: Analyze (javascript)
  • GitHub Check: build (22.x)
🔇 Additional comments (1)
apps/fxc-server/src/app/routes/meshbir.test.ts (1)

69-69: LGTM! Typo corrected.

The typo fix from 'unkown' to 'unknown' improves test readability without changing the test behavior.

Comment on lines +159 to +167
.map((json) => {
try {
return JSON.parse(json) as MeshBirMessage;
} catch {
console.error(`Error parsing meshbir ${json}`);
return undefined;
}
})
.filter((msg) => msg !== undefined)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Excellent error handling, but avoid logging sensitive data.

The try-catch wrapper around JSON.parse effectively prevents crashes from malformed queue entries, and filtering out undefined values maintains clean data flow.

However, logging the entire JSON string exposes sensitive user data including location coordinates and user identifiers.

Apply this diff to log parse errors without exposing PII:

       .map((json) => {
         try {
           return JSON.parse(json) as MeshBirMessage;
         } catch {
-          console.error(`Error parsing meshbir ${json}`);
+          console.error(`Error parsing meshbir message - invalid JSON format`);
           return undefined;
         }
       })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.map((json) => {
try {
return JSON.parse(json) as MeshBirMessage;
} catch {
console.error(`Error parsing meshbir ${json}`);
return undefined;
}
})
.filter((msg) => msg !== undefined)
.map((json) => {
try {
return JSON.parse(json) as MeshBirMessage;
} catch {
console.error(`Error parsing meshbir message - invalid JSON format`);
return undefined;
}
})
.filter((msg) => msg !== undefined)
🤖 Prompt for AI Agents
In apps/fetcher/src/app/trackers/meshbir.ts around lines 159 to 167, the catch
block logs the entire JSON string which can expose PII; change the error logging
to avoid printing the raw payload by logging a non-sensitive summary (e.g., an
error message plus a short fixed-length prefix, a truncated length, or a hash of
the payload) and include the parse error message or stack for debugging; ensure
the log never contains full coordinates or user identifiers and keep the record
of the failure (timestamp, queue id if available, truncated or hashed payload,
and error) so you can debug without exposing sensitive data.

@vicb vicb merged commit 666a062 into master Oct 26, 2025
6 checks passed
@vicb vicb deleted the vicb/meshbir branch October 26, 2025 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant