xref: /aosp_15_r20/frameworks/base/ravenwood/tools/hoststubgen/src/com/android/hoststubgen/Exceptions.kt (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1 /*
2  * Copyright (C) 2023 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 package com.android.hoststubgen
17 
18 import java.io.File
19 
20 /**
21  * We will not print the stack trace for exceptions implementing it.
22  */
23 interface UserErrorException
24 
25 /**
26  * Exceptions about parsing class files.
27  */
28 class ClassParseException(message: String) : Exception(message)
29 
30 /**
31  * Use it for internal exception that really shouldn't happen.
32  */
33 class HostStubGenInternalException(message: String) : Exception(message)
34 
35 /**
36  * Exceptions about the content in a jar file.
37  */
38 class InvalidJarFileException(message: String) : Exception(message), UserErrorException
39 
40 /**
41  * Exceptions missing classes, fields, methods, etc.
42  */
43 class UnknownApiException(message: String) : Exception(message), UserErrorException
44 
45 /**
46  * Exceptions related to invalid annotations -- e.g. more than one visibility annotation
47  * on a single API.
48  */
49 class InvalidAnnotationException(message: String) : Exception(message), UserErrorException
50 
51 /**
52  * We use this for general "user" errors.
53  */
54 class GeneralUserErrorException(message: String) : Exception(message), UserErrorException
55 
56 /** Base exception class for invalid command line arguments. */
57 open class ArgumentsException(message: String?) : Exception(message), UserErrorException
58 
59 /** Thrown when the same annotation is used with different annotation arguments. */
60 class DuplicateAnnotationException(annotationName: String?) :
61     ArgumentsException("Duplicate annotation specified: '$annotationName'")
62 
63 /** Thrown when an input file does not exist. */
64 class InputFileNotFoundException(filename: String) :
65     ArgumentsException("File '$filename' not found")
66 
ensureFileExistsnull67 fun String.ensureFileExists(): String {
68     if (!File(this).exists()) {
69         throw InputFileNotFoundException(this)
70     }
71     return this
72 }
73