Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package com.google.devtools.build.lib.util; |
| 16 | |
| 17 | /** |
| 18 | * An exception thrown by various error conditions that are severe enough to halt the command (e.g. |
| 19 | * even a --keep_going build). These typically need to signal to the handling code what happened. |
mschaller | 54c9f1e | 2020-03-20 08:23:50 -0700 | [diff] [blame] | 20 | * Therefore, these exceptions contain a {@link DetailedExitCode} specifying a numeric exit code and |
| 21 | * a detailed failure for the command to return. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 22 | * |
mschaller | 54c9f1e | 2020-03-20 08:23:50 -0700 | [diff] [blame] | 23 | * <p>When an instance of this exception is thrown, Bazel will try to halt the command as soon as |
| 24 | * reasonably possible. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 25 | */ |
| 26 | public class AbruptExitException extends Exception { |
| 27 | |
mschaller | 54c9f1e | 2020-03-20 08:23:50 -0700 | [diff] [blame] | 28 | private final DetailedExitCode detailedExitCode; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 29 | |
Googler | cc22385 | 2020-03-23 09:43:23 -0700 | [diff] [blame] | 30 | public AbruptExitException(DetailedExitCode detailedExitCode) { |
| 31 | super(detailedExitCode.getFailureDetail().getMessage()); |
mschaller | 54c9f1e | 2020-03-20 08:23:50 -0700 | [diff] [blame] | 32 | this.detailedExitCode = detailedExitCode; |
| 33 | } |
| 34 | |
| 35 | public AbruptExitException(DetailedExitCode detailedExitCode, Throwable cause) { |
Googler | cc22385 | 2020-03-23 09:43:23 -0700 | [diff] [blame] | 36 | super(detailedExitCode.getFailureDetail().getMessage(), cause); |
mschaller | 54c9f1e | 2020-03-20 08:23:50 -0700 | [diff] [blame] | 37 | this.detailedExitCode = detailedExitCode; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 40 | public ExitCode getExitCode() { |
mschaller | 54c9f1e | 2020-03-20 08:23:50 -0700 | [diff] [blame] | 41 | return detailedExitCode.getExitCode(); |
| 42 | } |
| 43 | |
| 44 | public DetailedExitCode getDetailedExitCode() { |
| 45 | return detailedExitCode; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 46 | } |
| 47 | } |