Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up the exit status for description fetch failures. #369

Merged
merged 1 commit into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Tools/GenerateCheckedInServices
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This script does work currently needed to regenerate the sources found
# in Source/GeneratedServices.

set -e
set -eu

# Where does this script live so we can hit things in the tree.
readonly ToolsDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
Expand Down
23 changes: 22 additions & 1 deletion Source/Tools/ServiceGenerator/SGMain.m
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ - (instancetype)initWithArgc:(int)argc argv:(char * const *)argv {
}

- (int)run {

while (self.state != SGMain_Done) {
@autoreleasepool {
switch (self.state) {
Expand Down Expand Up @@ -685,20 +684,29 @@ - (BOOL)collectAPIFromURL:(NSURL *)url
if (parseErr) {
[self reportError:@"(reply was JSON, but it failed to parse: %@)", parseErr];
}
if (self.status == 0) {
self.status = 14;
}
self.state = SGMain_Done;
return;
}

if (parseErr != nil) {
[self reportError:@"Failed to parse the api description %@, error: %@",
reportingName, parseErr];
if (self.status == 0) {
self.status = 15;
}
self.state = SGMain_Done;
return;
}

if (json == nil) {
// At this point, the data wasn't typed as json and there were no other errors, give up.
[self reportError:@"Response didn't appear to be JSON."];
if (self.status == 0) {
self.status = 16;
}
self.state = SGMain_Done;
return;
}
Expand All @@ -712,6 +720,9 @@ - (BOOL)collectAPIFromURL:(NSURL *)url

if (![api isKindOfClass:[GTLRDiscovery_RestDescription class]]) {
[self reportError:@"The api description doesn't appear to be a discovery REST description"];
if (self.status == 0) {
self.status = 17;
}
self.state = SGMain_Done;
return;
}
Expand Down Expand Up @@ -1111,6 +1122,9 @@ - (void)stateParseArgs {
NSURL *asURL = [NSURL URLWithString:urlString];
if (asURL == nil) {
[self reportError:@"Failed to make an url out of %@", urlString];
if (self.status == 0) {
self.status = 40;
}
self.state = SGMain_Done;
return;
}
Expand Down Expand Up @@ -1249,6 +1263,9 @@ - (void)stateDescribe {
NSURL *discoveryRestURL = [NSURL URLWithString:discoveryRestURLString];
if (discoveryRestURL == nil) {
[self reportError:@"Failed to make an url out of %@", discoveryRestURLString];
if (self.status == 0) {
self.status = 41;
}
self.state = SGMain_Done;
return;
} else {
Expand Down Expand Up @@ -1633,6 +1650,10 @@ static int SGMainInternal(int argc, char * const *argv) {
"%s There were one or more errors; check the full output for details.\n",
kERROR);
}
// Safety net to ensure printing any error fails the tool.
if (sg.printedError && !status) {
status = 99;
}
}
return status;
}
Expand Down