refactor: replace unsafe as Error assertions with type guards#11845
refactor: replace unsafe as Error assertions with type guards#11845christian-byrne wants to merge 1 commit intomainfrom
as Error assertions with type guards#11845Conversation
Adds toError() / getErrorMessage() helpers in @/utils/errorUtil and replaces all 7 production `as Error` call sites with proper narrowing. Adds an ESLint rule (no-restricted-syntax) banning new `as Error` assertions in source files. Refs #11429
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
✨ Finishing Touches🧪 Generate unit tests (beta)
Review rate limit: 0/5 reviews remaining, refill in 4 minutes and 26 seconds. Comment |
🎨 Storybook: ✅ Built — View Storybook |
🎭 Playwright: ✅ 1463 passed, 0 failed · 2 flaky📊 Browser Reports
|
📦 Bundle: 5.26 MB gzip 🔴 +75 BDetailsSummary
Category Glance App Entry Points — 22.6 kB (baseline 22.6 kB) • 🔴 +32 BMain entry bundles and manifests
Status: 1 added / 1 removed Graph Workspace — 1.24 MB (baseline 1.24 MB) • ⚪ 0 BGraph editor runtime, canvas, workflow orchestration
Status: 1 added / 1 removed Views & Navigation — 81.8 kB (baseline 81.8 kB) • ⚪ 0 BTop-level views, pages, and routed surfaces
Status: 11 added / 11 removed Panels & Settings — 489 kB (baseline 489 kB) • ⚪ 0 BConfiguration panels, inspectors, and settings screens
Status: 21 added / 21 removed User & Accounts — 17.6 kB (baseline 17.5 kB) • 🔴 +74 BAuthentication, profile, and account management bundles
Status: 7 added / 7 removed Editors & Dialogs — 112 kB (baseline 112 kB) • ⚪ 0 BModals, dialogs, drawers, and in-app editors
Status: 4 added / 4 removed UI Components — 62.9 kB (baseline 62.9 kB) • ⚪ 0 BReusable component library chunks
Status: 14 added / 14 removed Data & Services — 3.04 MB (baseline 3.04 MB) • 🔴 +147 BStores, services, APIs, and repositories
Status: 16 added / 16 removed / 1 unchanged Utilities & Hooks — 365 kB (baseline 365 kB) • 🔴 +908 BHelpers, composables, and utility bundles
Status: 26 added / 25 removed / 6 unchanged Vendor & Third-Party — 9.94 MB (baseline 9.94 MB) • ⚪ 0 BExternal libraries and shared vendor chunks
Status: 5 added / 5 removed / 11 unchanged Other — 8.84 MB (baseline 8.84 MB) • 🔴 +97 BBundles that do not match a named category
Status: 129 added / 129 removed / 6 unchanged ⚡ Performance
|
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #11845 +/- ##
===========================================
- Coverage 71.71% 55.44% -16.28%
===========================================
Files 1491 1383 -108
Lines 86207 70595 -15612
Branches 23313 19678 -3635
===========================================
- Hits 61822 39140 -22682
- Misses 23514 30928 +7414
+ Partials 871 527 -344
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 991 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Summary
Replaces all 7 production
as Errortype assertions with properinstanceof Errornarrowing or a newtoError()helper, and adds an ESLint rule to prevent new ones. First slice of #11429 (theas Errorcategory — 9 total occurrences, 7 production + 2 in a test file left untouched).Changes
src/utils/errorUtil.tsexportingtoError(value: unknown): ErrorandgetErrorMessage(value: unknown): string | undefined.toErrorreturns the value unchanged if already anError, otherwise wraps it (handles strings,undefined, JSON-serializable objects, and circular refs viaString()fallback).src/services/gateway/registrySearchGateway.ts—toError(error)forlastErrorassignment in fallback loopsrc/platform/cloud/onboarding/auth.ts(×2) —toError(error)forcaptureApiErrorSentry callssrc/renderer/extensions/vueNodes/widgets/composables/audio/useAudioRecorder.ts—toError(err)before forwarding tooptions.onErrorsrc/extensions/core/load3d/LoaderManager.ts— replacederror as Error & { response?: ... }cast insideisNotFoundErrorwith'response' in error+ nested narrowingapps/desktop-ui/src/stores/maintenanceTaskStore.ts— inlineerror instanceof Error ? error.message : String(error)apps/desktop-ui/src/components/maintenance/TaskListPanel.vue— inlineerror instanceof Error ? error.message : undefinedno-restricted-syntaxblock namedcomfy/no-unsafe-error-assertion) banningTSAsExpression TSTypeReference[typeName.name='Error']insrc/**andapps/*/src/**, with test files (*.test.ts,*.spec.ts) excluded.src/utils/errorUtil.test.ts.Review Focus
as Errorfor fixture construction; only 2 occurrences exist (inteamWorkspaceStore.test.tsanderrorDialog.spec.ts) and they're intentional.toErroris duplicated as inlineinstanceofnarrowing inapps/desktop-ui/rather than imported, since the desktop-ui workspace doesn't share@/utils/with the main app and adding a path mapping for one helper felt heavier than two inline guards.as-on-DOM categories (HTMLElement ×133, HTMLInputElement ×55, HTMLCanvasElement ×36, KeyboardEvent ×7, Element ×3, MouseEvent ×2, Event ×2) are intentionally left for follow-up PRs to keep this one reviewable.Refs #11429
┆Issue is synchronized with this Notion page by Unito