ErrorInfo.cause: must be an errorinfo if present, not a string#2169
ErrorInfo.cause: must be an errorinfo if present, not a string#2169SimonWoolf merged 1 commit intomainfrom
Conversation
ErrorInfo.cause should never have been permitted to be an Error or a string in the typings; if present it must be an ErrorInfo (spec TI1). AFAICS it's never a string, there were some places where it could be an Error which I've fixed.
WalkthroughThis PR narrows the type definitions and implementations of error cause handling across the codebase, restricting the cause parameter from accepting Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/common/lib/client/realtimechannel.ts (1)
76-81:⚠️ Potential issue | 🟠 MajorPublic typings for
errorReasondon't match the implementation in bothRealtimeChannelandConnection.Implementation at
src/common/lib/client/realtimechannel.tsline 80 declareserrorReason: ErrorInfo | nulland initializes it asnull(line 130), butably.d.tsstill declares both as non-nullable:
RealtimeChannel.errorReason: ErrorInfo(line 2452)Connection.errorReason: ErrorInfo(line 3263)This mismatch can mislead TypeScript consumers into unsafe dereferences. Update both declarations in
ably.d.tsto include| null.Suggested fix
- errorReason: ErrorInfo; + errorReason: ErrorInfo | null;Apply to both
RealtimeChannelandConnectioninterfaces inably.d.ts.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/common/lib/client/realtimechannel.ts` around lines 76 - 81, The public type for errorReason is declared non-nullable in ably.d.ts but the runtime classes RealtimeChannel and Connection set errorReason to null; update both interface/type declarations for RealtimeChannel.errorReason and Connection.errorReason in ably.d.ts to be nullable (ErrorInfo | null) so the typings match the implementation and avoid unsafe dereferences; ensure you change both occurrences (the RealtimeChannel and Connection definitions) consistently and run type checks.
🧹 Nitpick comments (1)
src/plugins/push/getW3CDeviceDetails.ts (1)
85-89: PreserveErrorInfocause when available (optional).
Right now you drop the cause even whenerris already anErrorInfo. You can retain it without violating the new contract and also avoid"undefined"whenerrisn’t anError.♻️ Suggested tweak
} catch (err) { - machine.handleEvent( - new GettingPushDeviceDetailsFailed( - new ErrorInfo('Failed to register service worker: ' + (err as Error).message, 50000, 500), - ), - ); + const cause = err instanceof ErrorInfo ? err : undefined; + const errMessage = err instanceof Error ? err.message : String(err); + machine.handleEvent( + new GettingPushDeviceDetailsFailed( + new ErrorInfo('Failed to register service worker: ' + errMessage, 50000, 500, cause), + ), + ); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/plugins/push/getW3CDeviceDetails.ts` around lines 85 - 89, In the catch block where you construct GettingPushDeviceDetailsFailed using new ErrorInfo(...), preserve the original error as the ErrorInfo cause when available: detect if err is already an ErrorInfo (or at least an Error) and pass it into the new ErrorInfo as the cause instead of dropping it; update the catch that creates new ErrorInfo(...) inside GettingPushDeviceDetailsFailed so it forwards err (when err instanceof ErrorInfo or err instanceof Error) as the cause argument to ErrorInfo to avoid "undefined" and retain original error details.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/common/lib/client/realtimechannel.ts`:
- Around line 76-81: The public type for errorReason is declared non-nullable in
ably.d.ts but the runtime classes RealtimeChannel and Connection set errorReason
to null; update both interface/type declarations for RealtimeChannel.errorReason
and Connection.errorReason in ably.d.ts to be nullable (ErrorInfo | null) so the
typings match the implementation and avoid unsafe dereferences; ensure you
change both occurrences (the RealtimeChannel and Connection definitions)
consistently and run type checks.
---
Nitpick comments:
In `@src/plugins/push/getW3CDeviceDetails.ts`:
- Around line 85-89: In the catch block where you construct
GettingPushDeviceDetailsFailed using new ErrorInfo(...), preserve the original
error as the ErrorInfo cause when available: detect if err is already an
ErrorInfo (or at least an Error) and pass it into the new ErrorInfo as the cause
instead of dropping it; update the catch that creates new ErrorInfo(...) inside
GettingPushDeviceDetailsFailed so it forwards err (when err instanceof ErrorInfo
or err instanceof Error) as the cause argument to ErrorInfo to avoid "undefined"
and retain original error details.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (6)
ably.d.tssrc/common/lib/client/realtimechannel.tssrc/common/lib/types/errorinfo.tssrc/platform/nodejs/lib/util/crypto.tssrc/platform/web/lib/util/crypto.tssrc/plugins/push/getW3CDeviceDetails.ts
ErrorInfo.cause should never have been permitted to be an Error or a string in the typings; if present it must be an ErrorInfo (TI1).
AFAICS it's never a string, there were some places where it could be an Error which I've fixed.
Summary by CodeRabbit