-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(bzlmod): throw on json parse exception #15109
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
@@ -115,7 +117,14 @@ private String constructUrl(String base, String... segments) { | |||
return Optional.empty(); | |||
} | |||
String jsonString = new String(bytes.get(), UTF_8); | |||
return Optional.of(gson.fromJson(jsonString, klass)); | |||
if (jsonString.strip().equals("")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the empty string treated specially?
also prefer using String#isEmpty
over equals("")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()));
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
You're welcome @Wyverald @meteorcloudy |
@bazel-io fork 5.2 |
1 similar comment
@bazel-io fork 5.2 |
[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 <tzayouna@gmail.com>
Fixes
Get rid of new lines in
bazel_registry.json
and return anOptional.empty()
aka registry descriptor without mirrors and throw an IOException for malformed JSON to stick to official json.org specs