refactor(error-handling): use unknown in catch blocks #337
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #310
Applied changes based on Issue #310.
I’ve enabled strict
unknown
typing for allcatch
variables and wired in a small helper to safely stringify them. Changes include:• tsconfig.json
– Turned on
"useUnknownInCatchVariables": true
to make allcatch
paramsunknown
.• src/utils/error.ts
– New module exporting
•
toErrorMessage(error: unknown): string
•
toErrorStack(error: unknown): string|undefined
• src/main.ts
– Imported the new helpers and unified the top‐level
catch
to always usetoErrorMessage
/toErrorStack
.• src/file/file.ts
– Imported
toErrorMessage
and protected all unguarded${error}
in itscatch
blocks.• src/github/event.ts
– Imported
toErrorMessage
and wrapped the JSON‐parse error intoErrorMessage
.• src/github/github.ts
– Imported
toErrorMessage
, and updated several rawcore.error(\
…${error}`)and
throw new Error(`…${error}`)` sites to use the helper instead.• src/security/security.ts
– Imported
toErrorMessage
and switched its twocore.warning(\
…${error}`)calls to
toErrorMessage(error)`.All existing catch‐blocks that already narrow via
instanceof Error
remain, but any raw${error}
is now safe.Next steps:
npm run format
to apply Prettier.npm run build
) and verify no TypeScript errors.npm test
).