6
6
// Please refer to the license found in the LICENSE file in the root directory of the source tree.
7
7
8
8
#import < Foundation/Foundation.h>
9
+ #import < os/log.h>
9
10
10
11
#import < executorch/runtime/platform/log.h>
11
- #import < os/log.h>
12
12
13
13
NS_ASSUME_NONNULL_BEGIN
14
14
@@ -18,15 +18,15 @@ extern NSErrorDomain const ETCoreMLErrorDomain;
18
18
// / The error codes that are exposed publicly.
19
19
typedef NS_ERROR_ENUM (ETCoreMLErrorDomain, ETCoreMLError) {
20
20
ETCoreMLErrorCorruptedData = 1 , // AOT blob can't be parsed.
21
- ETCoreMLErrorCorruptedMetadata, // AOT blob has incorrect or missing metadata.
22
- ETCoreMLErrorCorruptedModel, // AOT blob has incorrect or missing CoreML model.
23
- ETCoreMLErrorBrokenModel, // CoreML model doesn't match the input and output specification.
24
- ETCoreMLErrorCompilationFailed, // CoreML model failed to compile.
25
- ETCoreMLErrorModelCompilationNotSupported, // CoreML model compilation is not supported by the target.
26
- ETCoreMLErrorModelProfilingNotSupported, // Model profiling is not supported by the target.
27
- ETCoreMLErrorModelSaveFailed, // Failed to save CoreML model to disk.
28
- ETCoreMLErrorModelCacheCreationFailed, // Failed to create model cache.
29
- ETCoreMLErrorInternalError, // Internal error.
21
+ ETCoreMLErrorCorruptedMetadata = 2 , // AOT blob has incorrect or missing metadata.
22
+ ETCoreMLErrorCorruptedModel = 3 , // AOT blob has incorrect or missing CoreML model.
23
+ ETCoreMLErrorBrokenModel = 4 , // CoreML model doesn't match the input and output specification.
24
+ ETCoreMLErrorCompilationFailed = 5 , // CoreML model failed to compile.
25
+ ETCoreMLErrorModelCompilationNotSupported = 6 , // CoreML model compilation is not supported by the target.
26
+ ETCoreMLErrorModelProfilingNotSupported = 7 , // Model profiling is not supported by the target.
27
+ ETCoreMLErrorModelSaveFailed = 8 , // Failed to save CoreML model to disk.
28
+ ETCoreMLErrorModelCacheCreationFailed = 9 , // Failed to create model cache.
29
+ ETCoreMLErrorInternalError = 10 , // Internal error.
30
30
};
31
31
32
32
@interface ETCoreMLErrorUtils : NSObject
@@ -47,47 +47,47 @@ typedef NS_ERROR_ENUM(ETCoreMLErrorDomain, ETCoreMLError) {
47
47
#pragma clang diagnostic push
48
48
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
49
49
50
+ #if ET_LOG_ENABLED
51
+ #define ETCoreMLLogError (error, formatString, ...) \
52
+ do { \
53
+ NSString * message = error.localizedDescription ; \
54
+ message = [NSString stringWithFormat: @" [Core ML] " formatString " %@" , ##__VA_ARGS__, message]; \
55
+ ET_LOG (Error, " %s " , message.UTF8String ); \
56
+ } while (0 )
57
+ #else
58
+ #define ETCoreMLLogError (error, formatString, ...) \
59
+ os_log_error (ETCoreMLErrorUtils.loggingChannel, formatString " %@" , ##__VA_ARGS__, error.localizedDescription)
60
+ #endif
61
+
62
+ #if ET_LOG_ENABLED
63
+ #define ETCoreMLLogInfo (formatString, ...) \
64
+ ET_LOG (Info, " %s " , [NSString stringWithFormat: @formatString, ##__VA_ARGS__].UTF8String)
65
+ #else
66
+ #define ETCoreMLLogInfo (formatString, ...) os_log_info(ETCoreMLErrorUtils.loggingChannel, formatString, ##__VA_ARGS__)
67
+ #endif
68
+
50
69
// / Record the error with `os_log_error` and fills `*errorOut` with `NSError`.
51
- #define ETCoreMLLogErrorAndSetNSError (errorOut, errorCode, formatString, ...) \
52
- if (ET_LOG_ENABLED) { \
53
- ET_LOG (Error, " %s " , [NSString stringWithFormat: @formatString, ##__VA_ARGS__].UTF8String ); \
54
- } else { \
55
- os_log_error (ETCoreMLErrorUtils.loggingChannel , formatString, ##__VA_ARGS__); \
56
- } \
57
- if (errorOut) { \
58
- *errorOut = \
59
- [NSError errorWithDomain: ETCoreMLErrorDomain \
60
- code: errorCode \
61
- userInfo: @{ \
62
- NSLocalizedDescriptionKey : [NSString stringWithFormat: @formatString, ##__VA_ARGS__] \
63
- }]; \
64
- }
70
+ #define ETCoreMLLogErrorAndSetNSError (errorOut, errorCode, formatString, ...) \
71
+ do { \
72
+ NSDictionary * userInfo = \
73
+ @{ NSLocalizedDescriptionKey : [NSString stringWithFormat: @formatString, ##__VA_ARGS__] }; \
74
+ NSError * localError = [NSError errorWithDomain: ETCoreMLErrorDomain code: errorCode userInfo: userInfo]; \
75
+ ETCoreMLLogError (localError, " " ); \
76
+ if (errorOut) { \
77
+ *errorOut = localError; \
78
+ } \
79
+ } while (0 )
65
80
66
81
// / Record the error and its underlying error with `os_log_error` and fills `*errorOut` with `NSError`.
67
82
#define ETCoreMLLogUnderlyingErrorAndSetNSError (errorOut, errorCode, underlyingNSError, formatString, ...) \
68
- if (ET_LOG_ENABLED) { \
69
- ET_LOG (Error, " %s " , [NSString stringWithFormat: @formatString, ##__VA_ARGS__].UTF8String ); \
70
- } else { \
71
- os_log_error (ETCoreMLErrorUtils.loggingChannel , \
72
- formatString " , with underlying error= %@." , \
73
- ##__VA_ARGS__, \
74
- (underlyingNSError).localizedDescription ); \
75
- } \
76
- if (errorOut) { \
77
- *errorOut = [ETCoreMLErrorUtils errorWithCode: errorCode \
78
- underlyingError: underlyingNSError \
79
- format: @formatString, ##__VA_ARGS__]; \
80
- }
81
-
82
- #define ETCoreMLLogError (error, formatString, ...) \
83
- if (ET_LOG_ENABLED) { \
84
- ET_LOG (Error, " %s " , [NSString stringWithFormat: @formatString, ##__VA_ARGS__].UTF8String ); \
85
- } else { \
86
- os_log_error (ETCoreMLErrorUtils.loggingChannel , \
87
- formatString " , with error= %@." , \
88
- ##__VA_ARGS__, \
89
- (error).localizedDescription ); \
90
- }
83
+ do { \
84
+ ETCoreMLLogError (underlyingNSError, formatString, ##__VA_ARGS__); \
85
+ if (errorOut) { \
86
+ *errorOut = [ETCoreMLErrorUtils errorWithCode: errorCode \
87
+ underlyingError: underlyingNSError \
88
+ format: @formatString, ##__VA_ARGS__]; \
89
+ } \
90
+ } while (0 )
91
91
92
92
93
93
#pragma clang diagnostic pop
0 commit comments