Skip to content

feat(adapter-mariadb): Improve MariaDB adapter error reporting by surfacing underlying error causes - #28909

Merged
jacek-prisma merged 5 commits into
prisma:mainfrom
alireza-malek:feat/add-cause-mariadb-adapter
Dec 15, 2025
Merged

jacek-prisma merged 5 commits into
prisma:mainfrom
alireza-malek:feat/add-cause-mariadb-adapter

Conversation

@alireza-malek

@alireza-malek alireza-malek commented Dec 12, 2025 •

Copy link
Copy Markdown
Contributor

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” 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:

    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:

    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:

      ...
      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 without changing how errors are raised or handled elsewhere.

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.

✏️ Tip: You can customize this high-level summary in your review settings.

…errors

The `cause` property can now capture additional information about the error, enhancing debugging capabilities. Closes prisma#28612
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Dec 12, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds an optional cause field to the MariaDB adapter's internal DriverError, propagates the nested driver error message into the shared MappedError mysql variant as cause?: string, and adds tests verifying this mapping behavior.

Changes

Cohort / File(s) Summary
MariaDB adapter error implementation
packages/adapter-mariadb/src/errors.ts
Added cause?: SqlError to internal DriverError and updated mapDriverError/convertDriverError to propagate cause: error.cause?.message ?? undefined.
MariaDB adapter tests
packages/adapter-mariadb/src/errors.test.ts
Added tests asserting mapped error includes cause when driver error has a nested cause, and omits/undefines it when absent.
Shared adapter types
packages/driver-adapter-utils/src/types.ts
Extended MappedError kind: 'mysql' variant with optional cause?: string to carry nested driver messages.

Suggested reviewers

  • jacek-prisma

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: improving error reporting by surfacing underlying error causes in the MariaDB adapter.
Linked Issues check ✅ Passed The PR successfully addresses the core requirement from issue #28612 by propagating underlying driver error causes through a new cause field in the mapped error object.
Out of Scope Changes check ✅ Passed All code changes are directly related to implementing cause field propagation for error reporting; no unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

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

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 040fc8f and 08e62ff.

📒 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.ts that re-export from other modules). Import directly from the source file (e.g., import { foo } from './utils/query-utils' not import { foo } from './utils'), unless ./utils/index.ts file already exists

Files:

  • packages/driver-adapter-utils/src/types.ts
  • 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.ts file to MappedError kinds defined in packages/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 cause field 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.cause property 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.cause check is reasonable since cause can be various error object types.

Comment thread packages/adapter-mariadb/src/errors.ts Resolved
@jacek-prisma

Copy link
Copy Markdown
Contributor

Thanks for the contribution @alireza-malek!
I left one comment, the new field is causing some type errors, but it can be fixed pretty easily. Also I think the coderabbit comment is valid.

Refines the `cause` property in the `DriverError` type to use `SqlError` for better type safety.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/adapter-mariadb/src/errors.ts (1)

150-150: Consider using unknown for stronger type safety.

While SqlError is more specific than the previous any type mentioned in the coderabbitai comment, using unknown would 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

📥 Commits

Reviewing files that changed from the base of the PR and between 08e62ff and 88ae3bf.

📒 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.ts that re-export from other modules). Import directly from the source file (e.g., import { foo } from './utils/query-utils' not import { foo } from './utils'), unless ./utils/index.ts file already exists

Files:

  • packages/adapter-mariadb/src/errors.ts
  • packages/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.ts file to MappedError kinds defined in packages/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?: string field is appropriately typed as optional (addressing jacek-prisma's comment) and aligns with the implementation in packages/adapter-mariadb/src/errors.ts where 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 SqlError type from the mariadb library is the correct approach for typing the nested error cause.

Comment thread packages/adapter-mariadb/src/errors.ts Resolved

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/adapter-mariadb/src/errors.ts (1)

145-150: DriverError.cause should not be typed as SqlError (too narrow for runtime) — use unknown.
This is very likely what’s behind the “type errors” mentioned in the PR comments when the actual thrown error’s cause is not exactly SqlError. (Similar to prior feedback about avoiding any.)

 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

📥 Commits

Reviewing files that changed from the base of the PR and between 88ae3bf and d80784e.

📒 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.ts that re-export from other modules). Import directly from the source file (e.g., import { foo } from './utils/query-utils' not import { foo } from './utils'), unless ./utils/index.ts file 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.ts file to MappedError kinds defined in packages/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]

Comment thread packages/adapter-mariadb/src/errors.ts Resolved
Comment thread packages/adapter-mariadb/src/errors.ts Resolved

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f98dea and 069cead.

📒 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.ts that re-export from other modules). Import directly from the source file (e.g., import { foo } from './utils/query-utils' not import { foo } from './utils'), unless ./utils/index.ts file already exists

Files:

  • packages/adapter-mariadb/src/errors.test.ts
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Test files named *.test.ts are 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 undefined check on line 56 is particularly valuable—it ensures the cause field is truly absent rather than set to a falsy value, keeping the payload minimal and stable as noted in the comment.

@jacek-prisma
jacek-prisma merged commit 7e120ed into prisma:main Dec 15, 2025
jkomyno pushed a commit that referenced this pull request Dec 16, 2025
…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 -->
@delboy1978uk

Copy link
Copy Markdown

I'm looking forward to seeing this, can anyone say when this will be released? :-D

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.

MySQL pool timeout using adapter (rust free engine)

4 participants