Use DetailedExitCode in AbruptExitException
This allows code that constructs this exception to specify FailureDetail
values. Those are useful for communicating more information about failure
modes than just an exit code.
This modifies BuildTool to consume the exception's DetailedExitCode,
which is the first of many similar uses to be transformed.
---
To keep SkyDoc from depending on protobuf resources, this factors
AbruptExitException (which SkyDoc does not depend on) out of
devtools/build/lib:util (which SkyDoc does depend on). Rules which
previously depended on :util for AbruptExitException now directly
depend on its new rule.
RELNOTES: None.
PiperOrigin-RevId: 302031416
diff --git a/src/main/java/com/google/devtools/build/lib/util/AbruptExitException.java b/src/main/java/com/google/devtools/build/lib/util/AbruptExitException.java
index 3dabdfc..4158bd8 100644
--- a/src/main/java/com/google/devtools/build/lib/util/AbruptExitException.java
+++ b/src/main/java/com/google/devtools/build/lib/util/AbruptExitException.java
@@ -17,32 +17,51 @@
/**
* An exception thrown by various error conditions that are severe enough to halt the command (e.g.
* even a --keep_going build). These typically need to signal to the handling code what happened.
- * Therefore, these exceptions contain a recommended ExitCode allowing the exception to "set" a
- * returned numeric exit code.
+ * Therefore, these exceptions contain a {@link DetailedExitCode} specifying a numeric exit code and
+ * a detailed failure for the command to return.
*
- * When an instance of this exception is thrown, Blaze will try to halt as soon as reasonably
- * possible.
+ * <p>When an instance of this exception is thrown, Bazel will try to halt the command as soon as
+ * reasonably possible.
*/
public class AbruptExitException extends Exception {
- private final ExitCode exitCode;
+ private final DetailedExitCode detailedExitCode;
public AbruptExitException(String message, ExitCode exitCode) {
super(message);
- this.exitCode = exitCode;
+ this.detailedExitCode = DetailedExitCode.justExitCode(exitCode);
}
public AbruptExitException(String message, ExitCode exitCode, Throwable cause) {
super(message, cause);
- this.exitCode = exitCode;
+ this.detailedExitCode = DetailedExitCode.justExitCode(exitCode);
}
public AbruptExitException(ExitCode exitCode, Throwable cause) {
super(cause);
- this.exitCode = exitCode;
+ this.detailedExitCode = DetailedExitCode.justExitCode(exitCode);
+ }
+
+ public AbruptExitException(String message, DetailedExitCode detailedExitCode) {
+ super(message);
+ this.detailedExitCode = detailedExitCode;
+ }
+
+ public AbruptExitException(String message, DetailedExitCode detailedExitCode, Throwable cause) {
+ super(message, cause);
+ this.detailedExitCode = detailedExitCode;
+ }
+
+ public AbruptExitException(DetailedExitCode detailedExitCode, Throwable cause) {
+ super(cause);
+ this.detailedExitCode = detailedExitCode;
}
public ExitCode getExitCode() {
- return exitCode;
+ return detailedExitCode.getExitCode();
+ }
+
+ public DetailedExitCode getDetailedExitCode() {
+ return detailedExitCode;
}
}