Repository navigation
feat(adapter-mariadb): Improve MariaDB adapter error reporting by surfacing underlying error causes - #28909
Conversation
…errors The `cause` property can now capture additional information about the error, enhancing debugging capabilities. Closes prisma#28612
|
|
WalkthroughAdds an optional Changes
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
packages/adapter-mariadb/src/errors.ts(2 hunks)packages/driver-adapter-utils/src/types.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx,js,jsx}: Use kebab-case for new file names (e.g.,query-utils.ts,filter-operators.test.ts)
Avoid creating barrel files (index.tsthat re-export from other modules). Import directly from the source file (e.g.,import { foo } from './utils/query-utils'notimport { foo } from './utils'), unless./utils/index.tsfile already exists
Files:
packages/driver-adapter-utils/src/types.tspackages/adapter-mariadb/src/errors.ts
packages/adapter-*/src/errors.ts
📄 CodeRabbit inference engine (AGENTS.md)
For driver adapter error handling, map database-specific error codes in each adapter's
errors.tsfile toMappedErrorkinds defined inpackages/driver-adapter-utils/src/types.ts
Files:
packages/adapter-mariadb/src/errors.ts
🔇 Additional comments (2)
packages/driver-adapter-utils/src/types.ts (1)
176-176: LGTM! Addition of optional cause field enhances error diagnostics.The optional
causefield allows the MySQL/MariaDB adapter to surface underlying driver error details (e.g., RSA key retrieval failures, socket timeouts) while maintaining backward compatibility. The string type aligns with how the cause is stringified in the adapter's error mapping logic.packages/adapter-mariadb/src/errors.ts (1)
139-139: Line 139 is correct—no changes needed.The mariadb driver (v3.4.5) does populate the
error.causeproperty with nested errors from lower-level operations (pool timeouts, network issues, etc.). The defensive stringification logic appropriately captures these root cause diagnostics. The'toString' in error.causecheck is reasonable since cause can be various error object types.
|
Thanks for the contribution @alireza-malek! |
Refines the `cause` property in the `DriverError` type to use `SqlError` for better type safety.
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
packages/adapter-mariadb/src/errors.ts (1)
150-150: Consider usingunknownfor stronger type safety.While
SqlErroris more specific than the previousanytype mentioned in the coderabbitai comment, usingunknownwould be more honest about the type uncertainty. The defensive runtime check at line 141 ('toString' in error.cause) suggests we're not fully certain about the available methods on this type.type DriverError = { errno: number sqlMessage: string | null sqlState: string | null - cause?: SqlError + cause?: unknown }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
packages/adapter-mariadb/src/errors.ts(3 hunks)packages/driver-adapter-utils/src/types.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx,js,jsx}: Use kebab-case for new file names (e.g.,query-utils.ts,filter-operators.test.ts)
Avoid creating barrel files (index.tsthat re-export from other modules). Import directly from the source file (e.g.,import { foo } from './utils/query-utils'notimport { foo } from './utils'), unless./utils/index.tsfile already exists
Files:
packages/adapter-mariadb/src/errors.tspackages/driver-adapter-utils/src/types.ts
packages/adapter-*/src/errors.ts
📄 CodeRabbit inference engine (AGENTS.md)
For driver adapter error handling, map database-specific error codes in each adapter's
errors.tsfile toMappedErrorkinds defined inpackages/driver-adapter-utils/src/types.ts
Files:
packages/adapter-mariadb/src/errors.ts
🔇 Additional comments (2)
packages/driver-adapter-utils/src/types.ts (1)
176-176: LGTM! The optional cause field correctly addresses the previous review feedback.The
cause?: stringfield is appropriately typed as optional (addressing jacek-prisma's comment) and aligns with the implementation inpackages/adapter-mariadb/src/errors.tswhere the cause is stringified before being added to the mapped error.packages/adapter-mariadb/src/errors.ts (1)
2-2: LGTM! The import of SqlError type is appropriate.Importing the
SqlErrortype from the mariadb library is the correct approach for typing the nested error cause.
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
packages/adapter-mariadb/src/errors.ts (1)
145-150:DriverError.causeshould not be typed asSqlError(too narrow for runtime) — useunknown.
This is very likely what’s behind the “type errors” mentioned in the PR comments when the actual thrown error’scauseis not exactlySqlError. (Similar to prior feedback about avoidingany.)type DriverError = { errno: number sqlMessage: string | null sqlState: string | null - cause?: SqlError + cause?: unknown }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
packages/adapter-mariadb/src/errors.ts(3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx,js,jsx}: Use kebab-case for new file names (e.g.,query-utils.ts,filter-operators.test.ts)
Avoid creating barrel files (index.tsthat re-export from other modules). Import directly from the source file (e.g.,import { foo } from './utils/query-utils'notimport { foo } from './utils'), unless./utils/index.tsfile already exists
Files:
packages/adapter-mariadb/src/errors.ts
packages/adapter-*/src/errors.ts
📄 CodeRabbit inference engine (AGENTS.md)
For driver adapter error handling, map database-specific error codes in each adapter's
errors.tsfile toMappedErrorkinds defined inpackages/driver-adapter-utils/src/types.ts
Files:
packages/adapter-mariadb/src/errors.ts
🔇 Additional comments (1)
packages/adapter-mariadb/src/errors.ts (1)
134-142: [Your rewritten review comment text here]
[Exactly ONE classification tag]
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
packages/adapter-mariadb/src/errors.test.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx,js,jsx}: Use kebab-case for new file names (e.g.,query-utils.ts,filter-operators.test.ts)
Avoid creating barrel files (index.tsthat re-export from other modules). Import directly from the source file (e.g.,import { foo } from './utils/query-utils'notimport { foo } from './utils'), unless./utils/index.tsfile already exists
Files:
packages/adapter-mariadb/src/errors.test.ts
**/*.test.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Test files named
*.test.tsare excluded from build output via esbuild config; place tests alongside source files
Files:
packages/adapter-mariadb/src/errors.test.ts
🔇 Additional comments (2)
packages/adapter-mariadb/src/errors.test.ts (2)
1-5: LGTM!The imports are clean and the test suite is well-organized.
40-57: Excellent test validating cause omission when not available.The explicit
undefinedcheck on line 56 is particularly valuable—it ensures thecausefield is truly absent rather than set to a falsy value, keeping the payload minimal and stable as noted in the comment.
…facing underlying error causes (#28909) **Summary** The `mariadb` driver wraps connection‑level failures in a pool timeout error, but it also includes a nested `cause` with the real reason. This PR updates `@prisma/adapter-mariadb` error mapping so MySQL/MariaDB driver errors include the underlying driver cause (when present), instead of only surfacing the top-level pool timeout. Closes #28612 **Why** [Users were hitting errors like “pool timeout”](#28612) where the real root cause was attached by the MariaDB driver as a nested cause (e.g. socket connect timeout, RSA public key retrieval). Prisma surfaced only the outer message, so people couldn’t diagnose what to fix. **Behavior before vs after** - **Before:** ```text DriverAdapterError: pool timeout: failed to retrieve a connection from pool after 10008ms (pool connections: active=0 idle=0 limit=5) cause: { originalCode: '45028', originalMessage: 'pool timeout: failed to retrieve a connection from pool after 10008ms (pool connections: ...)', kind: 'mysql', code: 45028, message: 'pool timeout: failed to retrieve a connection from pool after 10008ms (pool connections: ...)', state: 'HY000' } ``` The underlying message about RSA public key retrieval or socket timeout was completely hidden. - **After:** ```text DriverAdapterError: pool timeout: failed to retrieve a connection from pool after 10008ms (pool connections: active=0 idle=0 limit=5) cause: { originalCode: '45028', originalMessage: 'pool timeout: failed to retrieve a connection from pool after 10008ms (pool connections: ...)', kind: 'mysql', code: 45028, message: 'pool timeout: failed to retrieve a connection from pool after 10008ms (pool connections: ...)', state: 'HY000', cause: 'SqlError: (conn:44, no: 45044, SQLState: 08S01) RSA public key is not available client side. Either set option `cachingRsaPublicKey` to indicate public key path, or allow public key retrieval with option `allowPublicKeyRetrieval`' } ``` Also applies to network issues like: ```text ... cause: 'SqlError: (conn:-1, no: 45012, SQLState: 08S01) Connection timeout: failed to create socket after 1003ms' } ``` Now users can immediately see whether the problem is TLS/SSL, authentication (RSA key retrieval), connectivity (socket timeout), etc., instead of only a generic pool timeout. --- **Notes** - This follows the existing convention in `driver-adapter-utils` of exposing additional detail in a `cause: string` field. - It avoids concatenating multiple messages into `message`, keeping the top-level error text focused while still surfacing full context via `cause`. - It is **backwards compatible**: It specifically fixes the diagnosability issues described in [#28612](#28612) without changing how errors are raised or handled elsewhere. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved MariaDB/MySQL adapter error reporting to include an optional underlying-cause field and to propagate nested error messages, providing richer diagnostic context in logs and error payloads. * **Tests** * Added tests validating error-mapping behavior with and without nested driver causes to ensure cause propagation and omission behave as expected. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
|
I'm looking forward to seeing this, can anyone say when this will be released? :-D |
Summary
The
mariadbdriver wraps connection‑level failures in a pool timeout error, but it also includes a nestedcausewith the real reason. This PR updates@prisma/adapter-mariadberror mapping so MySQL/MariaDB driver errors include the underlying driver cause (when present), instead of only surfacing the top-level pool timeout. Closes #28612Why
Users were hitting errors like “pool timeout” where the real root cause was attached by the MariaDB driver as a nested cause (e.g. socket connect timeout, RSA public key retrieval). Prisma surfaced only the outer message, so people couldn’t diagnose what to fix.
Behavior before vs after
Before:
The underlying message about RSA public key retrieval or socket timeout was completely hidden.
After:
Also applies to network issues like:
Now users can immediately see whether the problem is TLS/SSL, authentication (RSA key retrieval), connectivity (socket timeout), etc., instead of only a generic pool timeout.
Notes
driver-adapter-utilsof exposing additional detail in acause: stringfield.message, keeping the top-level error text focused while still surfacing full context viacause.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.