blob: 77e2f2b282d33b3b7e556cb4465a10174972905f [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
Austin Schuh2dd86a92022-09-14 21:19:23 -070017#if !os(WASI)
James Kuszmaul8e62b022022-03-22 09:33:25 -070018import Foundation
Austin Schuh2dd86a92022-09-14 21:19:23 -070019#else
20import SwiftOverlayShims
21#endif
James Kuszmaul8e62b022022-03-22 09:33:25 -070022
23/// Collection of thrown from the Flatbuffer verifier
24public enum FlatbuffersErrors: Error, Equatable {
25
Austin Schuh2dd86a92022-09-14 21:19:23 -070026 /// 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
James Kuszmaul8e62b022022-03-22 09:33:25 -070030 /// 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
James Kuszmaul8e62b022022-03-22 09:33:25 -070064}
Austin Schuh2dd86a92022-09-14 21:19:23 -070065
66#if !os(WASI)
67
68extension FlatbuffersErrors {
69 public static func == (
70 lhs: FlatbuffersErrors,
71 rhs: FlatbuffersErrors) -> Bool
72 {
73 lhs.localizedDescription == rhs.localizedDescription
74 }
75}
76
77#endif