Fix pg write error message - #686
Conversation
WalkthroughRenamed and reshaped a Postgres error schema in PgStorage.res and refactored executeBatch error handling in IO.res to normalize exceptions, parse generic PG error messages, surface specific UTF-8 encoding errors with table context, skip certain transaction-aborted messages, and avoid rethrowing by resolving to an empty array. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant IO.executeBatch as IO.executeBatch
participant DB as Postgres
participant PgSchema as PgStorage.pgErrorMessageSchema
Caller->>IO.executeBatch: invoke
IO.executeBatch->>DB: beginSql / batch ops
DB-->>IO.executeBatch: result or error (Promise)
IO.executeBatch->>IO.executeBatch: Promise.catch normalize exn
IO.executeBatch->>PgSchema: parse JsError(message)
alt message == "invalid byte sequence for encoding \"UTF8\": 0x00"
IO.executeBatch->>IO.executeBatch: set specificError = PgEncodingError{table}
else message == "current transaction is aborted..."
IO.executeBatch->>IO.executeBatch: no action
else other JsError / non-JsError
IO.executeBatch->>IO.executeBatch: prettify or ignore
end
IO.executeBatch-->>Caller: Promise.resolve([]) (no rethrow)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
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 unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
codegenerator/cli/templates/static/codegen/src/IO.res (4)
172-177: Normalization step is good; small improvement: prefer prettifyingnormalizedExnfor consistency.You normalize to an
exnonce; downstream, use this normalized value for prettification instead of the outerexnto avoid surprises whenreasonis already transformed.
200-200: Typo: “Improtant” → “Important”.Minor spelling fix in the user-facing comment.
- // Improtant: Don't rethrow here, since it'll result in + // Important: Don't rethrow here, since it'll result in
184-197: Optional: make matching resilient to minor message prefix/suffix variations.Some PG clients prepend severity or codes. If this shows up in your environment, consider relaxing the equality for the transaction-aborted case as well (e.g., startsWith/includes).
172-197: Optional: Preserve original PG error object in PgStorage.setOrThrow to enable reliable parsing here.Currently,
PgStorage.setOrThrowwraps non-schema errors asPersistence.StorageErrorwith a prettifiedreasonstring. That erases the original PG error object, making it harder to inspectmessagehere when entities (not history) fail. If feasible, change PgStorage to store the originalexninreasonand only prettify at presentation boundaries.I can draft that refactor if you’d like.
📜 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.
📒 Files selected for processing (2)
codegenerator/cli/npm/envio/src/PgStorage.res(1 hunks)codegenerator/cli/templates/static/codegen/src/IO.res(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{res,resi}
📄 CodeRabbit Inference Engine (.cursor/rules/rescript.mdc)
**/*.{res,resi}: Never use[| item |]to create an array. Use[ item ]instead.
Must always use=for setting value to a field. Use:=only for ref values created usingreffunction.
ReScript has record types which require a type definition before hand. You can access record fields by dot likefoo.myField.
It's also possible to define an inline object, it'll have quoted fields in this case.
Use records when working with structured data, and objects to conveniently pass payload data between functions.
Never use %raw to access object fields if you know the type.
Files:
codegenerator/cli/npm/envio/src/PgStorage.rescodegenerator/cli/templates/static/codegen/src/IO.res
codegenerator/cli/npm/envio/**
📄 CodeRabbit Inference Engine (.cursor/rules/navigation.mdc)
Library-fied runtime shared across indexers lives in codegenerator/cli/npm/envio.
Files:
codegenerator/cli/npm/envio/src/PgStorage.res
codegenerator/cli/templates/{dynamic/**/*.hbs,static/**}
📄 CodeRabbit Inference Engine (.cursor/rules/navigation.mdc)
Templates live under codegenerator/cli/templates: dynamic/ for Handlebars (.hbs), static/ for raw Rescript files copied verbatim.
Files:
codegenerator/cli/templates/static/codegen/src/IO.res
{**/generated/src/**/*.res,codegenerator/cli/templates/static/codegen/src/**/*.res,codegenerator/cli/templates/dynamic/codegen/src/**/*.res}
📄 CodeRabbit Inference Engine (.cursor/rules/navigation.mdc)
Runtime code lives in each project’s generated/src, but template versions (good for editing) are under codegenerator/cli/templates/static/codegen/src or codegenerator/cli/templates/dynamic/codegen/src.
Files:
codegenerator/cli/templates/static/codegen/src/IO.res
⏰ 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). (1)
- GitHub Check: build_and_test
🔇 Additional comments (1)
codegenerator/cli/templates/static/codegen/src/IO.res (1)
166-170: Comment explains an important transactional race. LGTM.The note clarifies why the catch resolves and relies on beginSql to fail. This context is helpful.
| | `current transaction is aborted, commands ignored until end of transaction block` => () | ||
| | `invalid byte sequence for encoding "UTF8": 0x00` => |
There was a problem hiding this comment.
Are these from the lib or our internal errors? Would rather not depend on string matching an external error. Do they have codes instead? Otherwise all good 👍🏼
There was a problem hiding this comment.
I didn't notice anything like this after a quick look.
Summary by CodeRabbit
Bug Fixes
Refactor