Skip to content

Commit

Permalink
fix(titus): Do not automatically assume all Titus exceptions are retr…
Browse files Browse the repository at this point in the history
…yable (#4044)
  • Loading branch information
robzienert committed Sep 25, 2019
1 parent 972fbc1 commit 21cc20a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public TitusException(String message) {

public TitusException(String message, Throwable cause) {
super(message, cause);
setRetryable(true);
setRetryable(isExceptionRetryable(cause));
}

public TitusException(Throwable cause) {
super(cause);
setRetryable(true);
setRetryable(isExceptionRetryable(cause));
}

public TitusException(String message, String userMessage) {
Expand All @@ -41,6 +41,16 @@ public TitusException(String message, String userMessage) {

public TitusException(String message, Throwable cause, String userMessage) {
super(message, cause, userMessage);
setRetryable(true);
setRetryable(isExceptionRetryable(cause));
}

private static boolean isExceptionRetryable(Throwable cause) {
final String message = cause.getMessage();
if (message == null) {
return true;
}

// If the request sent to Titus is invalid, there's no sense is retrying.
return !message.startsWith("INVALID_ARGUMENT");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2019 Netflix, Inc.
*
* 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 com.netflix.spinnaker.clouddriver.titus

import spock.lang.Specification
import spock.lang.Unroll

class TitusExceptionSpec extends Specification {

@Unroll
def "should set retryable=#retryable on message=#message"() {
given:
Exception downstream = new RuntimeException(message)

expect:
new TitusException("Something bad happened", downstream).retryable == retryable

where:
message || retryable
"INVALID_ARGUMENT: Image does not exist" || false
"Something else entirely" || true
}
}

0 comments on commit 21cc20a

Please sign in to comment.