use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project conjure-java by palantir.
the class SafeExchangeCompletionListenerTest method test_throwsRuntimeException.
@Test
public void test_throwsRuntimeException() {
Mockito.doThrow(new SafeIllegalArgumentException()).when(action).accept(exchange);
ExchangeCompletionListener listener = SafeExchangeCompletionListener.of(action);
listener.exchangeEvent(exchange, nextListener);
Mockito.verify(action).accept(exchange);
Mockito.verify(nextListener).proceed();
Mockito.verifyNoMoreInteractions(nextListener, action);
}
use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project conjure-java by palantir.
the class SafeExchangeCompletionListenerTest method test_proceedThrowsRuntimeException.
@Test
public void test_proceedThrowsRuntimeException() {
Mockito.doThrow(new SafeIllegalArgumentException()).when(nextListener).proceed();
ExchangeCompletionListener listener = SafeExchangeCompletionListener.of(action);
listener.exchangeEvent(exchange, nextListener);
Mockito.verify(action).accept(exchange);
Mockito.verify(nextListener).proceed();
Mockito.verifyNoMoreInteractions(nextListener, action);
}
use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project conjure-java-runtime-api by palantir.
the class UserAgents method parseInternal.
private static UserAgent parseInternal(String userAgent, boolean lenient) {
ImmutableUserAgent.Builder builder = ImmutableUserAgent.builder();
Matcher matcher = SEGMENT_PATTERN.matcher(userAgent);
boolean foundFirst = false;
while (matcher.find()) {
String name = matcher.group(1);
String version = matcher.group(2);
Optional<String> comments = Optional.ofNullable(matcher.group(4));
if (!foundFirst) {
// primary
builder.primary(UserAgent.Agent.of(name, version));
comments.ifPresent(c -> {
Map<String, String> parsedComments = parseComments(c);
if (parsedComments.containsKey("nodeId")) {
builder.nodeId(parsedComments.get("nodeId"));
}
});
} else {
// informational
builder.addInformational(UserAgent.Agent.of(name, version));
}
foundFirst = true;
}
if (!foundFirst) {
if (lenient) {
if (log.isDebugEnabled()) {
log.debug("Invalid user agent '{}', falling back to default/unknown agent", SafeArg.of("userAgent", userAgent));
}
return builder.primary(UserAgent.Agent.of("unknown", UserAgent.Agent.DEFAULT_VERSION)).build();
} else {
throw new SafeIllegalArgumentException("Failed to parse user agent string", SafeArg.of("userAgent", userAgent));
}
}
return builder.build();
}
use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project atlasdb by palantir.
the class ClusterMetadataUtils method getTableMetadata.
public static TableMetadata getTableMetadata(CqlMetadata metadata, String keyspace, String table) {
KeyspaceMetadata keyspaceMetadata = metadata.getKeyspaceMetadata(keyspace);
Optional<TableMetadata> maybeTable = keyspaceMetadata.getTables().stream().filter(tableMetadata -> tableMetadata.getName().equals(table)).collect(MoreCollectors.toOptional());
return maybeTable.orElseThrow(() -> new SafeIllegalArgumentException("Can't find table", SafeArg.of("keyspace", keyspace), LoggingArgs.tableRef("table", TableReference.fromString(table))));
}
use of com.palantir.logsafe.exceptions.SafeIllegalArgumentException in project atlasdb by palantir.
the class ColumnValueDescription method persistJsonToBytes.
@SuppressWarnings("unchecked")
public byte[] persistJsonToBytes(ClassLoader classLoader, String str) throws ParseException {
final byte[] bytes;
if (format == Format.PERSISTABLE) {
throw new SafeIllegalArgumentException("Tried to pass json into a persistable type.");
} else if (format == Format.PERSISTER) {
Persister<?> persister = getPersister();
if (JsonNode.class == persister.getPersistingClassType()) {
try {
JsonNode jsonNode = new ObjectMapper().readValue(str, JsonNode.class);
return ((Persister<JsonNode>) persister).persistToBytes(jsonNode);
} catch (IOException e) {
throw Throwables.throwUncheckedException(e);
}
} else {
throw new SafeIllegalArgumentException("Tried to write json to a Persister that isn't for JsonNode.");
}
} else if (format == Format.PROTO) {
Message.Builder builder = createBuilder(classLoader);
// This will have issues with base64 blobs
JsonFormat.merge(str, builder);
bytes = builder.build().toByteArray();
} else {
bytes = type.convertFromString(str);
}
return CompressionUtils.compress(bytes, compression);
}
Aggregations