Skip to content

Commit

Permalink
Print an error message when the downloader configuration file is miss…
Browse files Browse the repository at this point in the history
…ing.

Fixes bazelbuild#20058.

Closes bazelbuild#20061.

PiperOrigin-RevId: 580442451
Change-Id: Ic0a856e843428d655b6d11d437af7be76f3cc573
  • Loading branch information
tjgq authored and copybara-github committed Nov 8, 2023
1 parent b6f55bb commit 371e927
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
throw new AbruptExitException(
detailedExitCode(
String.format(
"Failed to parse downloader config at %s: %s", e.getLocation(), e.getMessage()),
"Failed to parse downloader config%s: %s",
e.getLocation() != null ? String.format(" at %s", e.getLocation()) : "",
e.getMessage()),
Code.BAD_DOWNLOADER_CONFIG));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -98,7 +97,7 @@ public static UrlRewriter getDownloaderUrlRewriter(String configPath, Reporter r
try (BufferedReader reader = Files.newBufferedReader(Paths.get(configPath))) {
return new UrlRewriter(log, configPath, reader);
} catch (IOException e) {
throw new UncheckedIOException(e);
throw new UrlRewriterParseException(e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@
// limitations under the License.
package com.google.devtools.build.lib.bazel.repository.downloader;

import javax.annotation.Nullable;
import net.starlark.java.syntax.Location;

/** An {@link Exception} thrown when failed to parse {@link UrlRewriterConfig}. */
public class UrlRewriterParseException extends Exception {
private final Location location;

public UrlRewriterParseException(String message, Location location) {
@Nullable private final Location location;

public UrlRewriterParseException(String message) {
this(message, /* location= */ null);
}

public UrlRewriterParseException(String message, @Nullable Location location) {
super(message);
this.location = location;
}

@Nullable
public Location getLocation() {
return location;
}
Expand Down

0 comments on commit 371e927

Please sign in to comment.