Skip to content

Commit

Permalink
Handle client connection errors
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Feb 28, 2024
1 parent b47f31f commit f5d6d9a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/io/seqera/wave/cli/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import io.seqera.wave.api.SubmitContainerTokenRequest;
import io.seqera.wave.api.SubmitContainerTokenResponse;
import io.seqera.wave.cli.exception.BadClientResponseException;
import io.seqera.wave.cli.exception.ClientConnectionException;
import io.seqera.wave.cli.exception.IllegalCliArgumentException;
import io.seqera.wave.cli.json.JsonHelper;
import io.seqera.wave.cli.util.BuildInfo;
Expand Down Expand Up @@ -231,7 +232,8 @@ else if( app.inspect ) {
app.run();
}
}
catch (IllegalCliArgumentException | CommandLine.ParameterException | BadClientResponseException e) {
catch (IllegalCliArgumentException | CommandLine.ParameterException | BadClientResponseException |
ClientConnectionException e) {
System.err.println(e.getMessage());
System.exit(1);
}
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/io/seqera/wave/cli/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.function.Predicate;

import dev.failsafe.Failsafe;
import dev.failsafe.FailsafeException;
import dev.failsafe.RetryPolicy;
import dev.failsafe.event.EventListener;
import dev.failsafe.event.ExecutionAttemptedEvent;
Expand All @@ -42,6 +43,7 @@
import io.seqera.wave.api.SubmitContainerTokenResponse;
import io.seqera.wave.cli.config.RetryOpts;
import io.seqera.wave.cli.exception.BadClientResponseException;
import io.seqera.wave.cli.exception.ClientConnectionException;
import io.seqera.wave.cli.json.JsonHelper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -103,8 +105,8 @@ ContainerInspectResponse inspect(ContainerInspectRequest request) {
throw new BadClientResponseException(msg);
}
}
catch (IOException e) {
throw new IllegalStateException("Unable to connect Wave service: " + endpoint);
catch (IOException | FailsafeException e) {
throw new ClientConnectionException("Unable to connect Wave service: " + endpoint, e);
}
}

Expand All @@ -128,8 +130,8 @@ SubmitContainerTokenResponse submit(SubmitContainerTokenRequest request) {
throw new BadClientResponseException(msg);
}
}
catch (IOException e) {
throw new IllegalStateException("Unable to connect Wave service: " + endpoint);
catch (IOException | FailsafeException e) {
throw new ClientConnectionException("Unable to connect Wave service: " + endpoint, e);
}
}

Expand Down Expand Up @@ -231,8 +233,8 @@ ServiceInfo serviceInfo() {
throw new BadClientResponseException(msg);
}
}
catch (IOException e) {
throw new IllegalStateException("Unable to connect Wave service: " + endpoint);
catch (IOException | FailsafeException e) {
throw new ClientConnectionException("Unable to connect Wave service: " + endpoint, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package io.seqera.wave.cli.exception;

/**
* Model a client response http error
*
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
*/
public class BadClientResponseException extends RuntimeException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023, Seqera Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package io.seqera.wave.cli.exception;

/**
* Model a generic client connection exception
*
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
*/
public class ClientConnectionException extends RuntimeException {

public ClientConnectionException(String message) {
super(message);
}

public ClientConnectionException(String message, Throwable cause) {
super(message, cause);
}

}

0 comments on commit f5d6d9a

Please sign in to comment.