refactor(error): route uncaught CLI errors through typed-error display#1238
refactor(error): route uncaught CLI errors through typed-error display#1238John-David Dalton (jdalton) wants to merge 3 commits intomainfrom
Conversation
The typed-error classes in `utils/error/errors.mts` (AuthError, InputError, ConfigError, NetworkError, FileSystemError, RateLimitError) plus the matching `formatErrorForDisplay`/`formatErrorForTerminal`/`formatErrorForJson` helpers were only ever exercised by tests — the CLI entry point used its own inline `if/else` dispatch that handled AuthError/InputError/Error. - Replace the inline dispatch in `cli-entry.mts` with calls to `formatErrorForTerminal` and `formatErrorForJson`, so any typed error now thrown in production gets consistent titles, recovery suggestions, and JSON/text formatting. - Convert `queryApi`'s "Socket API base URL is not configured" throw from a generic Error to a ConfigError keyed on CONFIG_KEY_API_BASE_URL. Users now see recovery suggestions directing them to `socket config set` instead of a bare stack trace. The remaining typed classes (NetworkError, FileSystemError, RateLimitError) stay parked. Forcing them into current CResult-returning sites would be a larger refactor and isn't needed for the display wiring itself to work — they slot in automatically the moment any throw site adopts them.
Addresses Cursor bugbot feedback on PR #1238. The previous code walked the cause chain only when `showStack`/verbose was set, so non-debug users lost the wrapped-error diagnostic context that `messageWithCauses` used to concatenate automatically. - Always fold up to 5 `Error.cause` messages into `message` for generic Error instances, so the outer message reads like `outer: middle: root` — matching `pony-cause`'s behavior. - The verbose/debug path still renders the richer `Caused by [N]:` formatted body with stack traces. - Add regression tests covering both the cause-chain preservation and the 5-level truncation cap.
|
Cursor (@cursor) review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit edf7906. Configure here.
|
Cursor (@cursor) review |
|
Cursor (@cursor) review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit e1525c5. Configure here.
|
Cursor (@cursor) review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit e1525c5. Configure here.
|
Cursor (@cursor) review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit e1525c5. Configure here.
|
Cursor (@cursor) review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit e1525c5. Configure here.
MAN (m74278803-cmyk)
left a comment
There was a problem hiding this comment.
this.container.appendChild (this.el);
this.ascend ( );
The heatmap you see visualizes the correlation matrix for your housing data. Here's a breakdown of what it tells us:
What is Correlation
Correlation measures the linear relationship between two variables.
A correlation coefficient ranges from
-1 to +1:
+1 (Dark Red): Indicates a perfect positive linear relationship.
As one variable increases, the other increases proportionally.
-1 (Dark Blue): Indicates a perfect negative linear relationship.
As one variable increases,
the other decreases proportionally.
0 (White/Gray): Indicates no linear relationship between the variables.
Interpreting the Heatmap:
Colors (cmap='coolwarm'):
The coolwarm colormap means warmer colors(reds) represent positive correlations, while cooler colors(blues) represent negative correlations.
The intensity of the color indicates the strength of the correlation.
Values(annot=True, fmt=".2f"):
The numbers displayed in each cell are the Pearson correlation coefficients,
rounded to two decimal places.
Diagonal: The diagonal elements are always 1 (dark red) because each variable is perfectly correlated with itself.
Symmetry: The matrix is symmetric, meaning the correlation between 'A' and 'B' is the same as between 'B' and 'A'.
Key Insights from your df_housing heatmap:
You can observe strong positive correlations between total_rooms, total_bedrooms, population, and households. This is expected, as more rooms usually mean more bedrooms, and larger populations would lead to more households.
median_income shows a noticeable positive correlation with median_house_value, which is a common finding: higher income areas tend to have higher house values.
longitude and latitude often show some correlation with other features due to geographical patterns in housing prices, but the relationships might not be strictly linear.
Summary
utils/error/errors.mts(AuthError,InputError,ConfigError,NetworkError,FileSystemError,RateLimitError) plusformatErrorForDisplay/formatErrorForTerminal/formatErrorForJsonwere only exercised by tests —cli-entry.mtsused its own inlineif/elsedispatch that handled onlyAuthError/InputError/Error.cli-entry.mtswithformatErrorForTerminal/formatErrorForJson, so any typed error thrown in production now gets consistent titles, recovery suggestions, and JSON/text formatting (includingCaused by [N]:chain walking andSuggested actions:blocks).queryApi's "Socket API base URL is not configured" throw from a genericErrorto aConfigErrorkeyed onCONFIG_KEY_API_BASE_URL. Users now see recovery suggestions directing them tosocket config setinstead of a bare stack trace.The remaining typed classes (
NetworkError,FileSystemError,RateLimitError) stay parked — forcing them into currentCResult-returning sites would be a larger refactor and isn't needed for the display wiring itself to work. They slot in automatically the moment any throw site adopts them.Test plan
pnpm --filter @socketsecurity/cli run test:unit test/unit/utils/error/— 144 passedpnpm --filter @socketsecurity/cli run test:unit test/unit/utils/socket/— 189 passedpnpm --filter @socketsecurity/cli run test:unit— 5104 passedpnpm run type— passespnpm run lint— passesNote
Medium Risk
Changes the CLI’s top-level exception handler and JSON/terminal error payloads, which may affect automation that parses output and alters user-facing diagnostics. Risk is limited to error-reporting paths (no auth/data-flow changes).
Overview
Uncaught CLI errors are now formatted via the shared typed-error display layer instead of an inline
if/elseincli-entry.mts, producing consistent terminal output and--jsonpayloads across error types.Spinner/error output interaction is fixed by stopping any active default spinner before printing top-level error text.
Error diagnostics are improved by including an
Error.causechain in the non-verbose message (depth-limited), with new unit tests covering cause preservation and truncation.Misconfiguration handling is made actionable by changing
queryApito throwConfigError(CONFIG_KEY_API_BASE_URL)when the API base URL is missing, enabling recovery suggestions.Reviewed by Cursor Bugbot for commit e1525c5. Configure here.