-
Notifications
You must be signed in to change notification settings - Fork 406
fix(shared): Rename static properties from 'name' to 'kind' in error classes #7004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: c1f6e90 The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughMultiple shared error classes were refactored to replace static Changes
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
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
…classes To fix local e2e errors where nextjs cannot assign static `name` prop
74ae614 to
495912f
Compare
There was a problem hiding this 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 fromnametokindfor consistency.The parameter is still named
name, but it now receives thekindvalue 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 versionNote: Also update the override in
ClerkAPIResponseErrorat 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
formatMessageparameter is renamed fromnametokind(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.
📒 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.tspackages/shared/src/errors/clerkApiError.tspackages/shared/src/errors/clerkApiResponseError.tspackages/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.tspackages/shared/src/errors/clerkApiError.tspackages/shared/src/errors/clerkApiResponseError.tspackages/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.tspackages/shared/src/errors/clerkApiError.tspackages/shared/src/errors/clerkApiResponseError.tspackages/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.tspackages/shared/src/errors/clerkApiError.tspackages/shared/src/errors/clerkApiResponseError.tspackages/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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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
Useconst assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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.tspackages/shared/src/errors/clerkApiError.tspackages/shared/src/errors/clerkApiResponseError.tspackages/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.tspackages/shared/src/errors/clerkApiError.tspackages/shared/src/errors/clerkApiResponseError.tspackages/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
kindis 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
kindproperty follows the pattern established across error classes. The inheritednamegetter fromClerkErrorwill still work correctly for thetoString()method at line 33.packages/shared/src/errors/createErrorTypeGuard.ts (2)
22-22: LGTM! Good backward compatibility approach.Adding the optional
kindproperty to the type definition allows the function to work with both old (usingname) and new (usingkind) error classes.
30-30: LGTM! Appropriate fallback for error messages.The fallback from
kindtonameprovides backward compatibility while preferring the newkindproperty. This ensures error messages are informative regardless of which pattern is used.
|
|
||
| export class ClerkError extends Error { | ||
| static name = 'ClerkError'; | ||
| static kind = 'ClerkError'; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
📒 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
…classes
To fix local e2e errors where nextjs cannot assign static
namepropDescription
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit