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