Skip to content

Commit

Permalink
Dialogue 'no addresses via DNS' exception is more standard (#2183)
Browse files Browse the repository at this point in the history
Dialogue 'no addresses via DNS' exception is more standard
  • Loading branch information
carterkozak authored Mar 4, 2024
1 parent a448898 commit f8e98a5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-2183.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Dialogue 'no addresses via DNS' exception is more standard
links:
- https://github.com/palantir/dialogue/pull/2183
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.palantir.dialogue.Channel;
import com.palantir.dialogue.Clients;
import com.palantir.dialogue.ConjureRuntime;
import com.palantir.dialogue.DialogueException;
import com.palantir.dialogue.Endpoint;
import com.palantir.dialogue.EndpointChannel;
import com.palantir.dialogue.EndpointChannelFactory;
Expand Down Expand Up @@ -572,8 +573,10 @@ private Refreshable<InternalDialogueChannel> getInternalDialogueChannel(String s
getTargetUris(serviceName, serviceConf.uris(), proxySelector(serviceConf.proxy()), resolvedHosts);

if (targetUris.isEmpty()) {
return new EmptyInternalDialogueChannel(() -> new SafeIllegalStateException(
"Service not available (no addresses via DNS)", SafeArg.of("serviceName", serviceName)));
return new EmptyInternalDialogueChannel(() -> new DialogueException(new SafeUnknownHostException(
"Service not available (no addresses via DNS)",
SafeArg.of("serviceName", serviceName),
UnsafeArg.of("uris", serviceConf.uris()))));
}

DialogueChannel dialogueChannel =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
*
* 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.palantir.dialogue.clients;

import com.google.errorprone.annotations.CompileTimeConstant;
import com.palantir.logsafe.Arg;
import com.palantir.logsafe.Safe;
import com.palantir.logsafe.SafeLoggable;
import com.palantir.logsafe.exceptions.SafeExceptions;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

final class SafeUnknownHostException extends UnknownHostException implements SafeLoggable {
@CompileTimeConstant
private final String logMessage;

private final List<Arg<?>> arguments;

SafeUnknownHostException(@CompileTimeConstant String message, Arg<?>... arguments) {
super(SafeExceptions.renderMessage(message, arguments));
this.logMessage = message;
this.arguments = Collections.unmodifiableList(Arrays.asList(arguments));
}

@Override
public @Safe String getLogMessage() {
return logMessage;
}

@Override
public List<Arg<?>> getArgs() {
return arguments;
}
}

0 comments on commit f8e98a5

Please sign in to comment.