Repository navigation
Show an error when an uploaded JSON file is not valid - #55498
Open
Ahmed-Manai wants to merge 2 commits into
Open
Ahmed-Manai wants to merge 2 commits into
Ahmed-Manai wants to merge 2 commits into
Conversation
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>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The upload handler catches form-conversion failures as JSON parse errors, misleading users into fixing nonexistent syntax errors in valid JSON.
80001 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #50402
JsonFileUploadswallowed JSON parse errors. It passed{}to the form and only loggedInvalid 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:
JsonFileUploadkeeps 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 markedvalidated="error". The error clears as soon as the content is valid or the file is cleared.onParseErrorprop.NewRealmFormuses it to keep Create disabled while the JSON is invalid.FileUploadFormgets an optionalerrorTextprop, shown instead of the help text. It also works withunWrap.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.
Tests
Added
should show an error for a resource file that is not valid JSONtotest/masthead/realm.spec.ts. It types invalid JSON into the resource file editor and checks two things:Ran
test/masthead/realm.spec.tsagainst the nightly server with the admin console served from Vite (KC_ADMIN_VITE_URL):tsc --noEmit, Prettier and ESLint are clean for the changed files.