-
Notifications
You must be signed in to change notification settings - Fork 382
fix(types, clerk-js): Update Errors interface to allow null for raw and global error arrays #6677
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
base: main
Are you sure you want to change the base?
Conversation
…nd global error arrays
🦋 Changeset detectedLatest commit: e644e1f The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types 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.
|
WalkthroughParsed error collections Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant Parser as parseErrors()
Caller->>Parser: parseErrors(error)
alt Not a Clerk API error
note over Parser: lazy init singleton arrays
Parser->>Parser: parsedErrors.raw = [error]
Parser->>Parser: parsedErrors.global = [error]
else Clerk API error with errors[]
loop For each item in error.errors
alt item.meta.paramName present
Parser->>Parser: Map item to fields[item.meta.paramName]
end
alt parsedErrors.global exists
Parser->>Parser: parsedErrors.global.push(item)
else
Parser->>Parser: parsedErrors.global = [item]
end
alt parsedErrors.raw exists
Parser->>Parser: parsedErrors.raw.push(item)
else
Parser->>Parser: parsedErrors.raw = [item]
end
end
end
Parser-->>Caller: parsedErrors (raw/global may be null)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
@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: |
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: 0
🧹 Nitpick comments (3)
packages/types/src/state.ts (1)
25-26
: Document new nullability on public API.Add JSDoc so integrators know to guard with a truthy check instead of
.length
.Apply:
export interface Errors { fields: FieldErrors; - raw: unknown[] | null; - global: unknown[] | null; + /** Null when there are no raw errors. Prefer `if (errors.raw)` over checking `.length`. */ + raw: unknown[] | null; + /** Null when there are no global errors. Prefer `if (errors.global)` over checking `.length`. */ + global: unknown[] | null; }packages/clerk-js/src/core/signals.ts (2)
70-75
: Condense lazy initialization and avoid shadowing.Use nullish-assignment to remove duplication and rename the loop variable to prevent shadowing the outer
error
.Apply:
- error.errors.forEach(error => { - if (parsedErrors.raw) { - parsedErrors.raw.push(error); - } else { - parsedErrors.raw = [error]; - } + error.errors.forEach(apiError => { + (parsedErrors.raw ??= []).push(apiError); - if ('meta' in error && error.meta && 'paramName' in error.meta) { - const name = snakeToCamel(error.meta.paramName); - parsedErrors.fields[name as keyof typeof parsedErrors.fields] = error; + if ('meta' in apiError && apiError.meta && 'paramName' in apiError.meta) { + const name = snakeToCamel(apiError.meta.paramName); + parsedErrors.fields[name as keyof typeof parsedErrors.fields] = apiError; return; } - if (parsedErrors.global) { - parsedErrors.global.push(error); - } else { - parsedErrors.global = [error]; - } + (parsedErrors.global ??= []).push(apiError); });Also applies to: 82-86
76-80
: Guard unknown param names to avoid writing outside known fields.If
snakeToCamel(paramName)
doesn’t matchFieldErrors
keys, fall back to global.Apply:
- if ('meta' in apiError && apiError.meta && 'paramName' in apiError.meta) { - const name = snakeToCamel(apiError.meta.paramName); - parsedErrors.fields[name as keyof typeof parsedErrors.fields] = apiError; - return; - } + if ('meta' in apiError && apiError.meta && 'paramName' in apiError.meta) { + const name = snakeToCamel(apiError.meta.paramName); + if (name && (name in parsedErrors.fields)) { + parsedErrors.fields[name as keyof typeof parsedErrors.fields] = apiError; + return; + } + }Also applies to: 82-86
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/clerk-js/src/core/signals.ts
(1 hunks)packages/types/src/state.ts
(1 hunks)
🧰 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/clerk-js/src/core/signals.ts
packages/types/src/state.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/clerk-js/src/core/signals.ts
packages/types/src/state.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/core/signals.ts
packages/types/src/state.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/clerk-js/src/core/signals.ts
packages/types/src/state.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
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
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
Useconst assertions
for literal types:as const
Usesatisfies
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 ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
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/clerk-js/src/core/signals.ts
packages/types/src/state.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/clerk-js/src/core/signals.ts
packages/types/src/state.ts
🧬 Code graph analysis (1)
packages/clerk-js/src/core/signals.ts (1)
packages/shared/src/underscore.ts (1)
snakeToCamel
(51-53)
⏰ 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). (6)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: semgrep/ci
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
packages/types/src/state.ts (2)
25-26
: Change aligns types with runtime (nullable raw/global).This matches the lazy initialization in clerk-js and enables simple truthy checks by consumers.
25-26
: No actionable call‐site changes needed.
Searches forerrors.global.length
,errors.raw.length
, optional‐chained/non‐null‐asserted.length
, and direct indexing returned no matches—there are no existing call sites to update.packages/clerk-js/src/core/signals.ts (2)
55-57
: Initialize to null to match updated types.Correctly mirrors
Errors
nullability.
64-66
: Non-API errors routed to raw/global as singletons.Good default; avoids empty arrays and keeps semantics consistent.
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
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
.changeset/red-tools-eat.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/red-tools-eat.md
🪛 LanguageTool
.changeset/red-tools-eat.md
[grammar] ~1-~1: Hier könnte ein Fehler sein.
Context: --- ---
(QB_NEW_DE)
⏰ 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). (23)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (tanstack-react-router, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Static analysis
- GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
--- | ||
--- |
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.
💡 Verification agent
🧩 Analysis chain
Changeset is empty/invalid — specify package bumps and summary.
Without valid frontmatter, CI release won’t pick this up. Given errors.raw/global
can now be null
at runtime and in types, this is plausibly a breaking change for TS consumers; consider a major bump (or confirm desired semver).
Apply this diff (adjust semver if you decide it’s minor/patch):
----
----
+---
+"@clerk/clerk-js": major
+"@clerk/types": major
+---
+
+Make `Errors.raw` and `Errors.global` nullable (`unknown[] | null`) and lazily initialized in clerk-js parsing.
+
+BREAKING (types/runtime): Code assuming arrays must now handle `null`.
+Migration:
+```ts
+if (errors.global) {
+ render(errors.global[0]?.message);
+}
+// or
+for (const e of errors.raw ?? []) { /* ... */ }
+```
🏁 Script executed:
#!/bin/bash
# Inspect the changeset file for missing frontmatter
cat .changeset/red-tools-eat.md
Length of output: 41
Populate .changeset/red-tools-eat.md
frontmatter
The file currently contains only empty markers; add valid package bumps and a summary so CI can detect this breaking change. Since errors.raw
/errors.global
now allow null
, this warrants a major bump (or confirm the desired semver).
----
----
+---
+"@clerk/clerk-js": major
+"@clerk/types": major
+---
+
+Make `Errors.raw` and `Errors.global` nullable (`unknown[] | null`) and lazily initialized in clerk-js parsing.
+
+BREAKING (types/runtime): Code assuming arrays must now handle `null`.
+Migration:
+```ts
+if (errors.global) {
+ render(errors.global[0]?.message);
+}
+// or
+for (const e of errors.raw ?? []) { /* ... */ }
+```
🧰 Tools
🪛 LanguageTool
[grammar] ~1-~1: Hier könnte ein Fehler sein.
Context: --- ---
(QB_NEW_DE)
🤖 Prompt for AI Agents
In .changeset/red-tools-eat.md around lines 1 to 2, the file contains only empty
markers and needs valid Changeset frontmatter so CI recognizes the release;
replace the empty frontmatter with a YAML block listing the affected package(s)
and their bump type (use "major" because errors.raw/errors.global now accept
null), and add a short summary sentence describing the breaking change (mention
errors.raw/errors.global allowing null and recommended migration notes). Ensure
the file has the standard three-dash delimiters, a "packages:" mapping with the
package names and "major" as the bump, and a non-empty body paragraph explaining
the change.
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.
Let's verify if an empty changeset is appropriate.
@@ -52,30 +52,38 @@ function errorsToParsedErrors(error: unknown): Errors { | |||
captcha: null, | |||
legalAccepted: null, | |||
}, | |||
raw: [], | |||
global: [], | |||
raw: null, |
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.
I hate that this is the case, but we need to update the default errors in the state proxy in clerk-react as well 😭
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.
Good catch!
Ill try to prioritize some tests to catch these sooner and a (potential) refactor later. Fixing...
Description
errors.global
can now be used without checking for the.length
property:Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
Bug Fixes
Refactor