Skip to content

Conversation

@tjenkinson
Copy link
Contributor

@tjenkinson tjenkinson commented Aug 15, 2025

Hey!

We have a block like

{
  "type": "quote",
  "blockId": "<snip>",
  "parent": "> <u>Table of Contents</u>",
  "children": [
    {
      "type": "table_of_contents",
      "blockId": "<snip>",
      "parent": "",
      "children": []
    }
  ]
}

where mdstr ends up being {}, which without this causes a crash

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a crash that occurred when processing content missing expected fields, ensuring the formatter handles empty or undefined inputs safely.
    • Maintains existing quote formatting behavior while improving reliability during content conversion.
    • Enhances overall stability when converting certain pages that previously caused runtime errors.

@coderabbitai
Copy link

coderabbitai bot commented Aug 15, 2025

Walkthrough

Introduces a nullish-coalescing default for formattedContent in src/notion-to-md.ts to ensure it is a string before splitting, preventing runtime errors when both mdstr.parent and mdstr[pageIdentifier] are undefined. Quote formatting behavior remains the same. No public APIs changed.

Changes

Cohort / File(s) Summary
Null-safe content formatting
src/notion-to-md.ts
Added nullish coalescing default to ensure formattedContent is a string prior to split; preserves existing quote prefixing and trimming logic; no exported/public signatures modified.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

I nibbled the code where nulls would creep,
Gave strings a cushion before their leap.
Now quotes march tidy, line by line—
No crashes, just formatting fine.
A hop, a fix, a safer run—
Carrot-commit: job well done! 🥕

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

We have a block like

```json
{
  "type": "quote",
  "blockId": "<snip>",
  "parent": "> <u>Table of Contents</u>",
  "children": [
    {
      "type": "table_of_contents",
      "blockId": "<snip>",
      "parent": "",
      "children": []
    }
  ]
}
```

where `mdstr` ends up being `{}`, which without this causes a crash
@tjenkinson tjenkinson marked this pull request as ready for review August 15, 2025 13:13
Copy link

@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: 0

🧹 Nitpick comments (1)
src/notion-to-md.ts (1)

153-159: Avoid stray blank line and de-duplicate conditions

When there’s no rendered child, the code still appends a newline (Line 159), which can produce an extra blank line. Also, the two branches append the same formattedContent. Merge the conditions and only append the newline when content is actually appended.

Apply this diff:

-          if (pageIdentifier !== "parent" && mdstr["parent"]) {
-            mdOutput[pageIdentifier] += formattedContent;
-          } else if (mdstr[pageIdentifier]) {
-            mdOutput[pageIdentifier] += formattedContent;
-          }
-
-          mdOutput[pageIdentifier] += "\n";
+          const hasRenderableChild =
+            (pageIdentifier !== "parent" && !!mdstr["parent"]) ||
+            !!mdstr[pageIdentifier];
+
+          if (hasRenderableChild) {
+            mdOutput[pageIdentifier] += formattedContent + "\n";
+          }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c751310 and cef9cd4.

📒 Files selected for processing (1)
  • src/notion-to-md.ts (1 hunks)
🔇 Additional comments (1)
src/notion-to-md.ts (1)

145-150: Defensive default prevents quote crash — LGTM

Using a nullish-coalescing fallback to an empty string ensures .split("\n") is always called on a string. This addresses the crash when a quote’s child (e.g., an empty table_of_contents) yields no rendered content without altering behavior for non-empty cases.

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