8000 Show an error when an uploaded JSON file is not valid by Ahmed-Manai · Pull Request #55498 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Show an error when an uploaded JSON file is not valid - #55498

Open
Ahmed-Manai wants to merge 2 commits into
keycloak:mainfrom
Ahmed-Manai:admin-ui-invalid-json-error
Open

Ahmed-Manai wants to merge 2 commits into
keycloak:mainfrom
Ahmed-Manai:admin-ui-invalid-json-error

Conversation

@Ahmed-Manai
Copy link
Copy Markdown

Closes #50402

JsonFileUpload swallowed JSON parse errors. It passed {} to the form and only logged Invalid json, ignoring value using {} to the browser console. In the Create realm dialog this meant a file with a syntax error left the realm name empty. If the name was then typed in by hand, Create made an empty realm, while the editor still showed the uploaded file as if it had been used.

With this change:

  • JsonFileUpload keeps the parse error and shows it under the field as an error helper text, for example The file is not valid JSON: Expected double-quoted property name in JSON at position 19 (line 1 column 20). The field is marked validated="error". The error clears as soon as the content is valid or the file is cleared.
  • It reports the error through a new optional onParseError prop. NewRealmForm uses it to keep Create disabled while the JSON is invalid.
  • FileUploadForm gets an optional errorText prop, shown instead of the help text. It also works with unWrap.
  • New message key: invalidJsonFile.

Partial import, the authorization settings import and the OpenID Connect discovery import use the same component, so they show the error too. Their behaviour is otherwise unchanged.

Create realm dialog with an invalid JSON file

Tests

Added should show an error for a resource file that is not valid JSON to test/masthead/realm.spec.ts. It types invalid JSON into the resource file editor and checks two things:

  • The error is shown and Create is disabled.
  • After the JSON is fixed, the error is gone, the realm name is filled in from the file and Create is enabled again.

Ran test/masthead/realm.spec.ts against the nightly server with the admin console served from Vite (KC_ADMIN_VITE_URL):

Chromium Firefox
Without the change new test fails (error text not found)
With the change 7 passed (twice) 7 passed (twice)

tsc --noEmit, Prettier and ESLint are clean for the changed files.

The JSON file upload in the admin console swallowed parse errors: the
form received an empty object and the error only went to the browser
console. When creating a realm this left the realm name empty and,
once filled in by hand, created an empty realm while the editor still
showed the uploaded file.

The upload now shows the parse error under the field and marks it as
invalid, and the Create realm dialog keeps Create disabled until the
JSON is valid. Partial import, the authorization import and the OpenID
Connect discovery import use the same component and show the error too.

Closes keycloak#50402

Signed-off-by: ahmed manai <manaii.ahmed9896@gmail.com>
@Ahmed-Manai
Ahmed-Manai requested review from a team as code owners November 24, 2026 21:16
Copilot AI balanced review requested due to automatic review settings November 24, 2026 21:16
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The upload handler catches form-conversion failures as JSON parse errors, misleading users into fixing nonexistent syntax errors in valid JSON.

8000
1 open issue
What changed in this PR

Addresses #50402 by showing JSON syntax errors in the admin console’s shared upload component and preventing realm creation while uploaded JSON is invalid.

Changes:

  • Displays parse errors inline and clears them when content becomes valid or is cleared.
  • Disables Create in the realm dialog while a parse error exists.
  • Adds a translated error message and a regression test for invalid-to-valid editor input.
File Description
js/​apps/​admin-ui/​test/​masthead/​realm.spec.ts Tests error visibility and Create button state as JSON is corrected.
js/​apps/​admin-ui/​src/​realm/​add/​NewRealmForm.tsx Uses parse-error state to disable realm creation.
js/​apps/​admin-ui/​src/​components/​json-file-upload/​JsonFileUpload.tsx Tracks parse errors and reports them through an optional callback.
js/​apps/​admin-ui/​src/​components/​json-file-upload/​FileUploadForm.tsx Adds error helper text and invalid field styling.
js/​apps/​admin-ui/​maven-resources/​theme/​keycloak.v2/​admin/​messages/​messages_en.properties Adds the English invalid-JSON message.

Review effort: Balanced

Errors thrown while the parsed object is applied to the form are no longer shown as a JSON syntax error.

Closes keycloak#50402

Signed-off-by: ahmed manai <manaii.ahmed9896@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 08:39
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are identified for the JSON upload error-handling change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show an error when the uploaded JSON file for creating a realm is syntactically invalid

2 participants

0