• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tools.metalava.cli.common
18 
19 /** Exceptions thrown by metalava CLI code. */
20 class MetalavaCliException(
21     /** The text that must be output to stderr, if it is blank then nothing is to be output. */
22     val stderr: String = "",
23 
24     /** The text that must be output to stdout, if it is blank then nothing is to be output. */
25     val stdout: String = "",
26 
27     /**
28      * The exit code for the process to return, defaults to `-1` if [stderr] is not blank, otherwise
29      * defaults to `0`.
30      */
31     val exitCode: Int = if (stderr.isBlank()) 0 else -1,
32 
33     /** Optional cause. */
34     cause: Throwable? = null,
35 ) : RuntimeException(stdout + stderr, cause)
36 
37 /**
38  * Throw a [MetalavaCliException] printing [message] to [stderr] and exiting with a non-zero exit
39  * code.
40  */
cliErrornull41 fun cliError(message: String): Nothing = throw MetalavaCliException(stderr = message)
42