Skip to content

Commit

Permalink
feat: improve JSON errors (ios-control#404)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
gabebear authored and shazron committed Aug 4, 2019
1 parent 2e1bda0 commit 7265dc6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/ios-deploy/ios-deploy.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@
if (err != 0) \
{ \
const char* msg = get_error_message(err); \
/*on_error("Error 0x%x: %s " #call, err, msg ? msg : "unknown.");*/ \
on_error(@"Error 0x%x: %@ " #call, err, msg ? [NSString stringWithUTF8String:msg] : @"unknown."); \
NSString *description = msg ? [NSString stringWithUTF8String:msg] : @"unknown."; \
NSLogJSON(@{@"Event": @"Error", @"Code": @(err), @"Status": description}); \
on_error(@"Error 0x%x: %@ " #call, err, description); \
} \
} while (false);

Expand Down Expand Up @@ -558,12 +559,18 @@ void mount_developer_image(AMDeviceRef device) {
} else if (result == 0xe8000076 /* already mounted */) {
NSLogOut(@"[ 95%%] Developer disk image already mounted");
} else {
if (result == 0xe80000e2 /* device locked */) {
NSLogOut(@"The device is locked.");
if (result != 0) {
const char* msg = get_error_message(result);
NSString *description = @"unknown.";
if (msg) {
description = [NSString stringWithUTF8String:msg];
NSLogOut(@"Error: %@", description);
}
NSLogJSON(@{@"Event": @"Error",
@"Status": @"DeviceLocked"
});
@"Code": @(result),
@"Status": description});
}

on_error(@"Unable to mount developer disk image. (%x)", result);
}

Expand Down

0 comments on commit 7265dc6

Please sign in to comment.