blob: 74c06b9aef3462157ee21c30b52bc3ac2ad7a447 [file] [log] [blame]
James Kuszmaul8e62b022022-03-22 09:33:25 -07001/*
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
17import Foundation
18
19/// Collection of thrown from the Flatbuffer verifier
20public enum FlatbuffersErrors: Error, Equatable {
21
22 /// Thrown when buffer is bigger than the allowed 2GiB
23 case exceedsMaxSizeAllowed
24 /// Thrown when there is an missaligned pointer at position
25 /// of type
26 case missAlignedPointer(position: Int, type: String)
27 /// Thrown when trying to read a value that goes out of the
28 /// current buffer bounds
29 case outOfBounds(position: UInt, end: Int)
30 /// Thrown when the signed offset is out of the bounds of the
31 /// current buffer
32 case signedOffsetOutOfBounds(offset: Int, position: Int)
33 /// Thrown when a required field doesnt exist within the buffer
34 case requiredFieldDoesntExist(position: VOffset, name: String)
35 /// Thrown when a string is missing its NULL Terminator `\0`,
36 /// this can be disabled in the `VerifierOptions`
37 case missingNullTerminator(position: Int, str: String?)
38 /// Thrown when the verifier has reached the maximum tables allowed,
39 /// this can be disabled in the `VerifierOptions`
40 case maximumTables
41 /// Thrown when the verifier has reached the maximum depth allowed,
42 /// this can be disabled in the `VerifierOptions`
43 case maximumDepth
44 /// Thrown when the verifier is presented with an unknown union case
45 case unknownUnionCase
46 /// thrown when a value for a union is not found within the buffer
47 case valueNotFound(key: Int?, keyName: String, field: Int?, fieldName: String)
48 /// thrown when the size of the keys vector doesnt match fields vector
49 case unionVectorSize(
50 keyVectorSize: Int,
51 fieldVectorSize: Int,
52 unionKeyName: String,
53 fieldName: String)
54 case apparentSizeTooLarge
55
56 public static func == (
57 lhs: FlatbuffersErrors,
58 rhs: FlatbuffersErrors) -> Bool
59 {
60 lhs.localizedDescription == rhs.localizedDescription
61 }
62}