fix(core): remove unsafe type assertion suppressions in error utils#19881
Conversation
Summary of ChangesHello @himanshu748, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the type safety of error utility functions by eliminating unsafe type assertions. The changes involve replacing direct Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully removes several eslint-disable comments for unsafe type assertions by refactoring the type-checking logic in error utility functions. The changes in errors.ts and quotaErrorDetection.ts improve code safety and readability.
I've added a couple of suggestions to further strengthen the type guards in quotaErrorDetection.ts. The current implementations for isApiError and isStructuredError are a bit weak and don't fully validate against their respective interfaces, which could lead to runtime issues. The suggested changes make these type guards more robust.
|
Enhanced isApiError and isStructuredError type guards with more robust validation of nested fields and types. |
Reverts errors.ts and quotaErrorDetection.ts to main branch versions. These type guard improvements belong in PR google-gemini#19881 which is dedicated to error utility type safety.
Remove 4 eslint-disable comments for @typescript-eslint/no-unsafe-type-assertion in quotaErrorDetection.ts and errors.ts by replacing unsafe `as` casts with proper runtime type narrowing using `in` operator checks and intermediate typed variables. Part of google-gemini#19440
isApiError now validates code (number), message (string), and status (string) properties instead of only checking for message existence. isStructuredError now validates status is a number when present. Both use 'in' operator checks to avoid unsafe type assertions.
836600f to
df4b407
Compare
Reverts errors.ts and quotaErrorDetection.ts to main branch versions. These type guard improvements belong in PR google-gemini#19881 which is dedicated to error utility type safety.
DavidAPierce
left a comment
There was a problem hiding this comment.
LGTM.
Thank you for your patience and contribution!
…oogle-gemini#19881) Co-authored-by: David Pierce <davidapierce@google.com>
Related to #19708
Summary
Remove 4
eslint-disablecomments for@typescript-eslint/no-unsafe-type-assertionin error utility files by replacing unsafeascasts with proper runtime type narrowing.Changes
packages/core/src/utils/quotaErrorDetection.ts(3 suppressions removed):isApiError(): Replaced(error as ApiError).errorwith early-return pattern and intermediateerrorPropvariableisStructuredError(): Replaced(error as StructuredError).messagewith(error as { message: unknown }).messagepackages/core/src/utils/errors.ts(1 suppression removed):isAuthenticationError(): UsedRecord<string, unknown>index access with explicitunknowntyping for safe narrowingTesting
npx eslintpasses on both files (0 errors)npm run testpasses (all tests green)