fix(bzlmod): throw on json parse exception#15109
Closed
Tomsons wants to merge 2 commits intobazelbuild:masterfrom
Closed
fix(bzlmod): throw on json parse exception#15109Tomsons wants to merge 2 commits intobazelbuild:masterfrom
Tomsons wants to merge 2 commits intobazelbuild:masterfrom
Conversation
Wyverald
reviewed
Mar 24, 2022
| } | ||
| String jsonString = new String(bytes.get(), UTF_8); | ||
| return Optional.of(gson.fromJson(jsonString, klass)); | ||
| if (jsonString.strip().equals("")) { |
Member
There was a problem hiding this comment.
why is the empty string treated specially?
also prefer using String#isEmpty over equals("")
Contributor
Author
There was a problem hiding this comment.
Sure, will come with another commit.
The empty string is treated specially because the bazel_registry.json can be empty without being explicitly declared as an empty json object {}, this should not throw an exception as it is simply ignored at getRepoSpec
if (bazelRegistryJson.isPresent() && bazelRegistryJson.get().mirrors != null) {
for (String mirror : bazelRegistryJson.get().mirrors) {
try {
new URL(mirror);
} catch (MalformedURLException e) {
throw new IOException("Malformed mirror URL", e);
}
urls.add(constructUrl(mirror, sourceUrl.getAuthority(), sourceUrl.getFile()));
}
}
Member
There was a problem hiding this comment.
I'd still rather the file always be valid JSON, but this is such a minor point that I won't push it. Thanks for the contribution!
Contributor
Author
|
You're welcome @Wyverald @meteorcloudy |
Contributor
|
@bazel-io fork 5.2 |
1 similar comment
Member
|
@bazel-io fork 5.2 |
This was referenced Mar 24, 2022
ckolli5
added a commit
that referenced
this pull request
May 9, 2022
[Fixes](#14437) Get rid of new lines in `bazel_registry.json` and return an `Optional.empty()` aka registry descriptor without mirrors and throw an IOException for malformed JSON to stick to official json.org specs Closes #15109. PiperOrigin-RevId: 436992309 Co-authored-by: Thomas Zayouna <[email protected]>
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.
Fixes
Get rid of new lines in
bazel_registry.jsonand return anOptional.empty()aka registry descriptor without mirrors and throw an IOException for malformed JSON to stick to official json.org specs