8000 fix(admin-ui): replace explicit `catch (error: any)` with proper types by pierluigilenoci · Pull Request #47397 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

fix(admin-ui): replace explicit catch (error: any) with proper types - #47397

Merged
ahus1 merged 2 commits into
keycloak:mainfrom
pierluigilenoci:cs/fix-error-types-17771
Apr 13, 2026
Merged

ahus1 merged 2 commits into
keycloak:mainfrom
pierluigilenoci:cs/fix-error-types-17771

Conversation

@pierluigilenoci
Copy link
Copy Markdown
Contributor

Summary

Remove all explicit : any annotations from catch clauses in the Admin UI, replacing them with proper type-safe error handling.

Since TypeScript's strict mode (with useUnknownInCatchVariables) already types catch variables as unknown, the explicit : any annotations were unnecessarily bypassing type safety.

Changes

7 catch blocks — simple removal of : any (error is only passed to addError(), which accepts unknown):

  • FlowDetails.tsx (2 catch blocks)
  • PasswordPolicy.tsx
  • AddKubernetesConnect.tsx
  • AddJWTAuthorizationGrant.tsx
  • AddSamlConnect.tsx
  • AddSpiffeConnect.tsx

2 catch blocks — replaced unsafe property access with type-safe utilities:

  • CreateFlow.tsx: replaced error.response?.data?.errorMessage || error with addError() (consistent with rest of codebase)
  • ClientScopesSection.tsx: replaced error.response?.data?.errorMessage || error with getErrorMessage() from @keycloak/keycloak-ui-shared

After this change, zero catch (error: any) remain in the entire JS monorepo.

Closes #17771

@pierluigilenoci
Copy link
Copy Markdown
Contributor Author

Hi @jonkoops, @edewit — this PR addresses the remaining catch (error: any) blocks flagged in #17771. All 9 occurrences have been fixed, and zero catch (error: any) remain in the JS monorepo after this change. Would you be willing to review? Thank you!

@pierluigilenoci
Copy link
Copy Markdown
Contributor Author

Gentle ping — this PR has been approved by @edewit and DCO is passing. @jonkoops @stianst would you be able to review or trigger the full CI pipeline? All 9 remaining catch (error: any) occurrences are fixed, completing the cleanup tracked in #17771. Thank you for your time!

@ahus1 ahus1 self-assigned this Apr 10, 2026
Remove all explicit `: any` annotations from catch clauses in the
Admin UI. Since TypeScript's `strict` mode (with
`useUnknownInCatchVariables`) already types catch variables as
`unknown`, the explicit `: any` annotations were unnecessarily
bypassing type safety.

For catch blocks that only pass the error to `addError()` (which
accepts `unknown`), the fix is simply removing the `: any` annotation.

For two catch blocks that performed unsafe property access on the
error (`error.response?.data?.errorMessage`), the fix replaces:
- `CreateFlow.tsx`: use `addError()` instead of manual message
  extraction (consistent with the rest of the codebase)
- `ClientScopesSection.tsx`: use `getErrorMessage()` from
  `@keycloak/keycloak-ui-shared` for type-safe error formatting

Closes #17771

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
@ahus1 ahus1 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pierluigilenoci - the linting fails, please fix. You can run the builds in your cloned repository to verify that they succeed.

@edewit - before approving PRs, please verify the CI buillds. If the CI builds didn't run for a first-time contributor, contact someone in your team that can approve them.

@pierluigilenoci
Copy link
Copy Markdown
Contributor Author

@ahus1 Thank you for the review — I'll investigate the linting failure and push a fix. Apologies for the oversight.

Collapse multi-line console.warn arguments onto a single line
in ClientScopesSection.tsx to fix the prettier/prettier lint error.

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
@pierluigilenoci
Copy link
Copy Markdown
Contributor Author

Fixed the linting issue — the console.warn call in ClientScopesSection.tsx was split across multiple lines, causing a prettier/prettier error. Collapsed it to a single line. Thank you @ahus1 for the review!

@ahus1 ahus1 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving based on @edewit's review.

8000
@ahus1
ahus1 merged commit cdb21c6 into keycloak:main Apr 13, 2026
63 checks passed
@stianst stianst mentioned this pull request Jun 1, 2026
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
keycloak#47397)

Remove all explicit `: any` annotations from catch clauses in the
Admin UI. Since TypeScript's `strict` mode (with
`useUnknownInCatchVariables`) already types catch variables as
`unknown`, the explicit `: any` annotations were unnecessarily
bypassing type safety.

For catch blocks that only pass the error to `addError()` (which
accepts `unknown`), the fix is simply removing the `: any` annotation.

For two catch blocks that performed unsafe property access on the
error (`error.response?.data?.errorMessage`), the fix replaces:
- `CreateFlow.tsx`: use `addError()` instead of manual message
  extraction (consistent with the rest of the codebase)
- `ClientScopesSection.tsx`: use `getErrorMessage()` from
  `@keycloak/keycloak-ui-shared` for type-safe error formatting

Closes keycloak#17771

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Caught errors should have the correct type associated with them

3 participants

0