Skip to content

Conversation

@nikosdouvlis
Copy link
Member

@nikosdouvlis nikosdouvlis commented Oct 16, 2025

…classes

To fix local e2e errors where nextjs cannot assign static name prop

Description

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Refactor
    • Standardized how error types are identified across the library, updating the public error identifier format for more consistent runtime identification and message construction.

@changeset-bot
Copy link

changeset-bot bot commented Oct 16, 2025

🦋 Changeset detected

Latest commit: c1f6e90

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@clerk/shared Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/clerk-js Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/clerk-expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Oct 16, 2025 8:41am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 16, 2025

Walkthrough

Multiple shared error classes were refactored to replace static name identifiers with static kind properties; the createErrorTypeGuard utility was updated to accept/error-match against kind with a fallback to name.

Changes

Cohort / File(s) Summary
API response error
packages/shared/src/errors/clerkApiResponseError.ts
Replaced static name with static kind on ClerkAPIResponseError
Runtime error
packages/shared/src/errors/clerkRuntimeError.ts
Replaced static name with static kind on ClerkRuntimeError
Base ClerkError
packages/shared/src/errors/clerkError.ts
Renamed static namekind; constructor now uses new.target.kind when formatting messages
API error instance → static
packages/shared/src/errors/clerkApiError.ts
Removed instance readonly name and introduced static kind = 'ClerkApiError'
Type guard utility
packages/shared/src/errors/createErrorTypeGuard.ts
Accepts ErrorClass: T & { kind?: string }; runtime message references ErrorClass.kind with fallback to ErrorClass.name
Changeset
.changeset/twelve-horses-mix.md
Added changeset documenting the rename from name to kind for shared errors

Sequence Diagram(s)

(Skipped — changes are refactoring of static identifiers and do not introduce new control-flow interactions.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through code with nimble mind,

Swapped name for kind, left bugs behind.
Static flags set, neat and spry,
A tiny change — a brighter sky. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title succinctly describes the main change by indicating a fix in the shared package that renames static properties from “name” to “kind” in error classes, matching the core modifications in the diff and following conventional commit style for clarity.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch nikos/fix-e2e-locally

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 16, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@7004

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@7004

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@7004

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@7004

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@7004

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@7004

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@7004

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@7004

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@7004

@clerk/express

npm i https://pkg.pr.new/@clerk/express@7004

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@7004

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@7004

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@7004

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@7004

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@7004

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@7004

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@7004

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@7004

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@7004

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@7004

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@7004

@clerk/types

npm i https://pkg.pr.new/@clerk/types@7004

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@7004

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@7004

commit: c1f6e90

…classes

To fix local e2e errors where nextjs cannot assign static `name` prop
Copy link
Contributor

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/shared/src/errors/clerkError.ts (1)

61-61: Rename parameter from name to kind for consistency.

The parameter is still named name, but it now receives the kind value from line 49. This is confusing and inconsistent with the refactoring.

Apply this diff to improve clarity:

-  protected static formatMessage(name: string, msg: string, code: string, docsUrl: string | undefined) {
+  protected static formatMessage(kind: string, msg: string, code: string, docsUrl: string | undefined) {
     // Keeping the Clerk prefix for backward compatibility
-    // msg = `${name}: ${msg.trim()}\n\n(code="${code}")\n\n`;
+    // msg = `${kind}: ${msg.trim()}\n\n(code="${code}")\n\n`;
     // We can remove the Clerk prefix in the next major version

Note: Also update the override in ClerkAPIResponseError at line 45 to maintain consistency.

🧹 Nitpick comments (1)
packages/shared/src/errors/clerkApiResponseError.ts (1)

45-47: Update parameter name to match base class recommendation.

If the base class formatMessage parameter is renamed from name to kind (as suggested), this override should also be updated for consistency.

-  protected static override formatMessage(name: string, msg: string, _: string, __: string | undefined) {
+  protected static override formatMessage(kind: string, msg: string, _: string, __: string | undefined) {
     return msg;
   }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 74ae614 and 495912f.

📒 Files selected for processing (5)
  • packages/shared/src/errors/clerkApiError.ts (1 hunks)
  • packages/shared/src/errors/clerkApiResponseError.ts (1 hunks)
  • packages/shared/src/errors/clerkError.ts (2 hunks)
  • packages/shared/src/errors/clerkRuntimeError.ts (1 hunks)
  • packages/shared/src/errors/createErrorTypeGuard.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/shared/src/errors/clerkRuntimeError.ts
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/shared/src/errors/createErrorTypeGuard.ts
  • packages/shared/src/errors/clerkApiError.ts
  • packages/shared/src/errors/clerkApiResponseError.ts
  • packages/shared/src/errors/clerkError.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/shared/src/errors/createErrorTypeGuard.ts
  • packages/shared/src/errors/clerkApiError.ts
  • packages/shared/src/errors/clerkApiResponseError.ts
  • packages/shared/src/errors/clerkError.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/shared/src/errors/createErrorTypeGuard.ts
  • packages/shared/src/errors/clerkApiError.ts
  • packages/shared/src/errors/clerkApiResponseError.ts
  • packages/shared/src/errors/clerkError.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/shared/src/errors/createErrorTypeGuard.ts
  • packages/shared/src/errors/clerkApiError.ts
  • packages/shared/src/errors/clerkApiResponseError.ts
  • packages/shared/src/errors/clerkError.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/shared/src/errors/createErrorTypeGuard.ts
  • packages/shared/src/errors/clerkApiError.ts
  • packages/shared/src/errors/clerkApiResponseError.ts
  • packages/shared/src/errors/clerkError.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/shared/src/errors/createErrorTypeGuard.ts
  • packages/shared/src/errors/clerkApiError.ts
  • packages/shared/src/errors/clerkApiResponseError.ts
  • packages/shared/src/errors/clerkError.ts
⏰ 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). (5)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (4)
packages/shared/src/errors/clerkApiError.ts (1)

11-11: LGTM! Consistent with error class refactoring.

The change from instance property to static kind is appropriate and aligns with the pattern used across other error classes.

packages/shared/src/errors/clerkApiResponseError.ts (1)

16-16: LGTM! Consistent with error class refactoring.

The static kind property follows the pattern established across error classes. The inherited name getter from ClerkError will still work correctly for the toString() method at line 33.

packages/shared/src/errors/createErrorTypeGuard.ts (2)

22-22: LGTM! Good backward compatibility approach.

Adding the optional kind property to the type definition allows the function to work with both old (using name) and new (using kind) error classes.


30-30: LGTM! Appropriate fallback for error messages.

The fallback from kind to name provides backward compatibility while preferring the new kind property. This ensures error messages are informative regardless of which pattern is used.


export class ClerkError extends Error {
static name = 'ClerkError';
static kind = 'ClerkError';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Add TypeScript constraint for subclass static kind property.

While the static kind property works for this base class, there's no type-level constraint ensuring that subclasses define their own static kind. This is critical because line 49 uses new.target.kind, which will be undefined if a subclass omits this property, potentially causing runtime errors in formatMessage.

Consider adding an abstract static accessor or documenting the requirement:

 export class ClerkError extends Error {
   static kind = 'ClerkError';
+  // Subclasses must define their own static kind property
   readonly clerkError = true as const;

Alternatively, provide a runtime check in the constructor:

constructor(opts: ClerkErrorParams) {
  const kind = (this.constructor as typeof ClerkError).kind;
  if (!kind) {
    throw new Error(`${this.constructor.name} must define a static 'kind' property`);
  }
  super(new.target.formatMessage(kind, opts.message, opts.code, opts.docsUrl), { cause: opts.cause });
  // ...
}
🤖 Prompt for AI Agents
In packages/shared/src/errors/clerkError.ts around line 37, enforce that
subclasses provide a static kind to avoid new.target.kind being undefined: add
an abstract static getter (e.g. abstract static get kind(): string) to the
ClerkError class signature so TypeScript forces subclasses to declare it, and
update the constructor to reference new.target.kind as before; additionally
(optional) add a small runtime guard in the constructor that throws a clear
Error if the resolved kind is falsy to catch any JS consumers.

Copy link
Contributor

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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 495912f and c1f6e90.

📒 Files selected for processing (1)
  • .changeset/twelve-horses-mix.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
.changeset/**

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/twelve-horses-mix.md
🪛 LanguageTool
.changeset/twelve-horses-mix.md

[grammar] ~5-~5: There might be a mistake here.
Context: ...static properties from 'name' to 'kind' in ClerkError class

(QB_NEW_EN)

⏰ 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). (27)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Static analysis
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan

"@clerk/shared": patch
---

Rename static properties from 'name' to 'kind' in ClerkError class
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Clarify scope of the change.

The rename applies to multiple error classes/utilities, not just ClerkError. Please update the note so downstream readers understand the broader impact.

🧰 Tools
🪛 LanguageTool

[grammar] ~5-~5: There might be a mistake here.
Context: ...static properties from 'name' to 'kind' in ClerkError class

(QB_NEW_EN)

🤖 Prompt for AI Agents
In .changeset/twelve-horses-mix.md around line 5, the note incorrectly limits
the rename to only the ClerkError class; update the changelog entry to state
that static property 'name' has been renamed to 'kind' across multiple error
classes and related utilities (e.g., ClerkError and other error
subclasses/utilities) so downstream consumers understand the broader,
codebase-wide impact; make the wording explicit and include a brief list or
phrase such as "applies to ClerkError and other error classes/utilities" and
mention any public APIs affected.

@nikosdouvlis nikosdouvlis changed the title fix(shared): Rename static properties from 'name' to 'kind' in error … fix(shared): Rename static properties from 'name' to 'kind' in error classes Oct 16, 2025
@nikosdouvlis nikosdouvlis merged commit d8147fb into main Oct 16, 2025
43 checks passed
@nikosdouvlis nikosdouvlis deleted the nikos/fix-e2e-locally branch October 16, 2025 09:02
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.

3 participants