[PR #7639] [MERGED] feat(i18n): type inference for error codes #15705

Closed
opened 2026-04-13 10:10:59 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7639
Author: @himself65
Created: 1/27/2026
Status: Merged
Merged: 1/28/2026
Merged by: @himself65

Base: canaryHead: himself65/2026/01/27/raw-error


📝 Commits (6)

📊 Changes

12 files changed (+108 additions, -56 deletions)

View changed files

📝 packages/better-auth/src/client/client.test.ts (+16 -16)
📝 packages/better-auth/src/client/react/index.ts (+2 -4)
📝 packages/better-auth/src/client/types.ts (+6 -9)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.test.ts (+1 -1)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.test.ts (+4 -4)
📝 packages/core/src/error/codes.ts (+13 -0)
📝 packages/core/src/types/context.ts (+7 -3)
📝 packages/core/src/types/index.ts (+5 -1)
📝 packages/core/src/types/plugin.ts (+9 -5)
📝 packages/core/src/utils/error-codes.ts (+12 -9)
📝 packages/i18n/src/types.ts (+31 -2)

📄 Description

Summary by cubic

Adds type-safe i18n error code translations inferred from installed plugins, improving DX and reducing missing-key errors. Also unifies error code typing in core and adjusts error string behavior.

  • New Features

    • i18n TranslationDictionary now suggests error code keys from all registered plugins (via BetterAuthPluginRegistry).
    • Plugins can expose $ERROR_CODES typed as RawError; base error codes are registered via an internal "$internal:base" entry.
    • defineErrorCodes returns RawError objects; BetterAuthPluginErrorCodePart is exported for plugin authors.
  • Migration

    • If you relied on error.toString() for the message, use error.message. toString() now returns the error code.

Written for commit 80778ba27d. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7639 **Author:** [@himself65](https://github.com/himself65) **Created:** 1/27/2026 **Status:** ✅ Merged **Merged:** 1/28/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2026/01/27/raw-error` --- ### 📝 Commits (6) - [`05df2f1`](https://github.com/better-auth/better-auth/commit/05df2f19caeda803d42a3b69bdaca12a960c2856) feat(i18n): type inference for error codes - [`fb4958b`](https://github.com/better-auth/better-auth/commit/fb4958b22f2009285e6b5c2931368a8c8f45b929) fix: remove unused - [`316a855`](https://github.com/better-auth/better-auth/commit/316a855d7499402c342d4677e0506a38aaa4ef48) fix: type - [`448df9c`](https://github.com/better-auth/better-auth/commit/448df9c6e48df6abfa42efab0ccaf9494a7e72f9) fix: error - [`4738492`](https://github.com/better-auth/better-auth/commit/4738492d6e8d3f70c249172ebd951b9c4260573c) chore: fix test - [`80778ba`](https://github.com/better-auth/better-auth/commit/80778ba27df6d59a546b70b535144a5fea3c4660) chore: fix ### 📊 Changes **12 files changed** (+108 additions, -56 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/client/client.test.ts` (+16 -16) 📝 `packages/better-auth/src/client/react/index.ts` (+2 -4) 📝 `packages/better-auth/src/client/types.ts` (+6 -9) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.test.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.test.ts` (+4 -4) 📝 `packages/core/src/error/codes.ts` (+13 -0) 📝 `packages/core/src/types/context.ts` (+7 -3) 📝 `packages/core/src/types/index.ts` (+5 -1) 📝 `packages/core/src/types/plugin.ts` (+9 -5) 📝 `packages/core/src/utils/error-codes.ts` (+12 -9) 📝 `packages/i18n/src/types.ts` (+31 -2) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds type-safe i18n error code translations inferred from installed plugins, improving DX and reducing missing-key errors. Also unifies error code typing in core and adjusts error string behavior. - **New Features** - i18n TranslationDictionary now suggests error code keys from all registered plugins (via BetterAuthPluginRegistry). - Plugins can expose $ERROR_CODES typed as RawError; base error codes are registered via an internal "$internal:base" entry. - defineErrorCodes returns RawError objects; BetterAuthPluginErrorCodePart is exported for plugin authors. - **Migration** - If you relied on error.toString() for the message, use error.message. toString() now returns the error code. <sup>Written for commit 80778ba27df6d59a546b70b535144a5fea3c4660. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 10:11:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#15705