xref: /aosp_15_r20/external/flatbuffers/swift/Sources/FlatBuffers/FlatbuffersErrors.swift (revision 890232f25432b36107d06881e0a25aaa6b473652)
1 /*
2  * Copyright 2021 Google Inc. All rights reserved.
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 #if !os(WASI)
18 import Foundation
19 #else
20 import SwiftOverlayShims
21 #endif
22 
23 /// Collection of thrown from the Flatbuffer verifier
24 public enum FlatbuffersErrors: Error, Equatable {
25 
26   /// Thrown when verifying a file id that doesnt match buffer id
27   case bufferIdDidntMatchPassedId
28   /// Prefixed size doesnt match the current (readable) buffer size
29   case prefixedSizeNotEqualToBufferSize
30   /// Thrown when buffer is bigger than the allowed 2GiB
31   case exceedsMaxSizeAllowed
32   /// Thrown when there is an missaligned pointer at position
33   /// of type
34   case missAlignedPointer(position: Int, type: String)
35   /// Thrown when trying to read a value that goes out of the
36   /// current buffer bounds
37   case outOfBounds(position: UInt, end: Int)
38   /// Thrown when the signed offset is out of the bounds of the
39   /// current buffer
40   case signedOffsetOutOfBounds(offset: Int, position: Int)
41   /// Thrown when a required field doesnt exist within the buffer
42   case requiredFieldDoesntExist(position: VOffset, name: String)
43   /// Thrown when a string is missing its NULL Terminator `\0`,
44   /// this can be disabled in the `VerifierOptions`
45   case missingNullTerminator(position: Int, str: String?)
46   /// Thrown when the verifier has reached the maximum tables allowed,
47   /// this can be disabled in the `VerifierOptions`
48   case maximumTables
49   /// Thrown when the verifier has reached the maximum depth allowed,
50   /// this can be disabled in the `VerifierOptions`
51   case maximumDepth
52   /// Thrown when the verifier is presented with an unknown union case
53   case unknownUnionCase
54   /// thrown when a value for a union is not found within the buffer
55   case valueNotFound(key: Int?, keyName: String, field: Int?, fieldName: String)
56   /// thrown when the size of the keys vector doesnt match fields vector
57   case unionVectorSize(
58     keyVectorSize: Int,
59     fieldVectorSize: Int,
60     unionKeyName: String,
61     fieldName: String)
62   case apparentSizeTooLarge
63 
64 }
65 
66 #if !os(WASI)
67 
68 extension FlatbuffersErrors {
69     public static func == (
70       lhs: FlatbuffersErrors,
71       rhs: FlatbuffersErrors) -> Bool
72     {
73       lhs.localizedDescription == rhs.localizedDescription
74     }
75 }
76 
77 #endif
78