Skip to content

Commit

Permalink
On error, use always exit code 1 instead of -1
Browse files Browse the repository at this point in the history
  • Loading branch information
jordeu committed Dec 15, 2021
1 parent 1c9ef35 commit 58b3014
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/java/io/seqera/tower/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void run() {
sendPeriodicHeartbeat();
} catch (Exception e) {
logger.error(e.getMessage());
System.exit(-1);
System.exit(1);
}
}

Expand All @@ -112,7 +112,7 @@ private void connectTower() {
final URI uri = new URI(url + "/agent/" + agentKey + "/connect");
if (!uri.getScheme().equals("https")) {
logger.error("You are trying to connect to an insecure server: {}", url);
System.exit(-1);
System.exit(1);
}

final MutableHttpRequest<?> req = HttpRequest.GET(uri).bearerAuth(token);
Expand Down Expand Up @@ -165,7 +165,7 @@ private void execCommand(CommandRequest message) {
agentClient.send(response);
} catch (Exception e) {
// send result
CommandResponse response = new CommandResponse(message.getId(), e.getMessage().getBytes(), -1);
CommandResponse response = new CommandResponse(message.getId(), e.getMessage().getBytes(), 1);
agentClient.send(response);
}
}
Expand Down Expand Up @@ -200,7 +200,7 @@ private void validateParameters() throws IOException {
validatedUserName = System.getProperty("user.name");
if (validatedUserName == null || validatedUserName.isEmpty() || validatedUserName.isBlank()) {
logger.error("Impossible to detect current Unix username.");
System.exit(-1);
System.exit(1);
}

// Set default workDir
Expand All @@ -210,14 +210,14 @@ private void validateParameters() throws IOException {
workDir = Paths.get(defaultPath);
} catch (InvalidPathException e) {
logger.error("Impossible to define a default work directory. Please provide one using '--work-dir'.");
System.exit(-1);
System.exit(1);
}
}

// Validate workDir exists
if (!Files.exists(workDir)) {
logger.error("The work directory '{}' do not exists. Create it or provide a different one using '--work-dir'.", workDir);
System.exit(-1);
System.exit(1);
}
validatedWorkDir = workDir.toAbsolutePath().normalize().toString();

Expand Down Expand Up @@ -246,7 +246,7 @@ private void checkTower() {

if (systemApiVersion.compareTo(requiredApiVersion) < 0) {
logger.error("Tower at '{}' is running API version {} and the agent needs a minimum of {}", url, systemApiVersion, requiredApiVersion);
System.exit(-1);
System.exit(1);
}
}
} catch (Exception e) {
Expand All @@ -255,7 +255,7 @@ private void checkTower() {
} else {
logger.error("Tower API endpoint '{}' it is not available (did you mean '{}/api'?)", url, url);
}
System.exit(-1);
System.exit(1);
}

try {
Expand All @@ -264,7 +264,7 @@ private void checkTower() {
httpClient.retrieve(req).blockingFirst();
} catch (Exception e) {
logger.error("Invalid TOWER_ACCESS_TOKEN, check that the given token has access at '{}'.", url);
System.exit(-1);
System.exit(1);
}
}

Expand Down

0 comments on commit 58b3014

Please sign in to comment.