Skip to content

Commit 7265dc6

Browse files
gabebearshazron
authored andcommitted
feat: improve JSON errors (ios-control#404)
* Improve JSON errors Add codes for errors and send all check_error() errors out as the JSON stream * Standardize on "Status" instead of "Description" * Better handling of the messages for both JSON and console.
1 parent 2e1bda0 commit 7265dc6

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/ios-deploy/ios-deploy.m

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@
121121
if (err != 0) \
122122
{ \
123123
const char* msg = get_error_message(err); \
124-
/*on_error("Error 0x%x: %s " #call, err, msg ? msg : "unknown.");*/ \
125-
on_error(@"Error 0x%x: %@ " #call, err, msg ? [NSString stringWithUTF8String:msg] : @"unknown."); \
124+
NSString *description = msg ? [NSString stringWithUTF8String:msg] : @"unknown."; \
125+
NSLogJSON(@{@"Event": @"Error", @"Code": @(err), @"Status": description}); \
126+
on_error(@"Error 0x%x: %@ " #call, err, description); \
126127
} \
127128
} while (false);
128129

@@ -558,12 +559,18 @@ void mount_developer_image(AMDeviceRef device) {
558559
} else if (result == 0xe8000076 /* already mounted */) {
559560
NSLogOut(@"[ 95%%] Developer disk image already mounted");
560561
} else {
561-
if (result == 0xe80000e2 /* device locked */) {
562-
NSLogOut(@"The device is locked.");
562+
if (result != 0) {
563+
const char* msg = get_error_message(result);
564+
NSString *description = @"unknown.";
565+
if (msg) {
566+
description = [NSString stringWithUTF8String:msg];
567+
NSLogOut(@"Error: %@", description);
568+
}
563569
NSLogJSON(@{@"Event": @"Error",
564-
@"Status": @"DeviceLocked"
565-
});
570+
@"Code": @(result),
571+
@"Status": description});
566572
}
573+
567574
on_error(@"Unable to mount developer disk image. (%x)", result);
568575
}
569576

0 commit comments

Comments
 (0)