blob: ab0bc40dab06031830a009519ea2827976b5e4a1 [file] [log] [blame]
Jens Geyer56e5b9b2015-10-09 22:01:55 +02001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#import "TError.h"
21
22
23extern NSString *TProtocolErrorDomain;
24
25typedef NS_ENUM (int, TProtocolError) {
26 TProtocolErrorUnknown = 0,
27 TProtocolErrorInvalidData = 1,
28 TProtocolErrorNegativeSize = 2,
29 TProtocolErrorSizeLimit = 3,
30 TProtocolErrorBadVersion = 4,
31 TProtocolErrorNotImplemented = 5,
32 TProtocolErrorDepthLimit = 6,
33};
34
35
36typedef NS_ENUM(int, TProtocolExtendedError) {
37 TProtocolExtendedErrorMissingRequiredField = 1001,
38 TProtocolExtendedErrorUnexpectedType = 1002,
39 TProtocolExtendedErrorMismatchedProtocol = 1003,
40};
41
42extern NSString *TProtocolErrorExtendedErrorKey;
43extern NSString *TProtocolErrorFieldNameKey;
44extern NSString *TProtocolErrorExpectedIdKey;
45extern NSString *TProtocolErrorExpectedVersionKey;
46extern NSString *TProtocolErrorTypeKey;
47extern NSString *TProtocolErrorSourceLineKey;
48extern NSString *TProtocolErrorSourceFileKey;
49extern NSString *TProtocolErrorSourceMethodKey;
50extern NSString *TProtocolErrorMessageNameKey;
51
52
53#define PROTOCOL_ERROR(ret, err, ...) \
54 if (error) { \
55 *error = [NSError errorWithDomain:TProtocolErrorDomain \
56 code:TProtocolError ## err \
57 userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:__VA_ARGS__], \
58 @"SourceFile": [NSString stringWithUTF8String:__FILE__], \
59 @"SourceLine": @(__LINE__), \
60 @"SourceFunction": [NSString stringWithUTF8String:__PRETTY_FUNCTION__], \
61 @"Message": self.currentMessageName ? self.currentMessageName : @""}]; \
62 } \
63 return ret
64
65#define PROTOCOL_TRANSPORT_ERROR(ret, errorPtr, ...) \
66 if (errorPtr) { \
67 *error = [NSError errorWithDomain:TProtocolErrorDomain \
68 code:TProtocolErrorUnknown \
69 userInfo:@{NSLocalizedDescriptionKey: [[NSString stringWithFormat:__VA_ARGS__] stringByAppendingFormat:@": %@", [(*errorPtr) localizedDescription]], \
70 TProtocolErrorSourceFileKey: [NSString stringWithUTF8String:__FILE__], \
71 TProtocolErrorSourceLineKey: @(__LINE__), \
72 TProtocolErrorSourceMethodKey: [NSString stringWithUTF8String:__PRETTY_FUNCTION__], \
73 TProtocolErrorMessageNameKey: self.currentMessageName ? self.currentMessageName : @"", \
74 NSUnderlyingErrorKey: *errorPtr}]; \
75 } \
76 return ret