public final void run(String[] args) { Options options = new Options(); Stream.of(optionsToAdd).forEach(options::addOption); CommandLineParser parser = new DefaultParser(); HelpFormatter help = new HelpFormatter(); try { CommandLine commandLine = parser.parse(options, args); run(commandLine); } catch (ParseException e) { log.error(() -> "Invalid input: " + e.getMessage()); help.printHelp(getClass().getSimpleName(), options); throw new Error(); } catch (Exception e) { log.error(() -> "Script execution failed.", e); throw new Error(); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { boolean channelInUse = getAttribute(ctx, ChannelAttributeKey.IN_USE).orElse(false); if (channelInUse) { ctx.fireExceptionCaught(cause); } else { ctx.close(); Optional<CompletableFuture<Void>> executeFuture = getAttribute(ctx, ChannelAttributeKey.EXECUTE_FUTURE_KEY); if (executeFuture.isPresent() && !executeFuture.get().isDone()) { log.error(() -> "An exception occurred on an channel (" + ctx.channel().id() + ") that was not in use, " + "but was associated with a future that wasn't completed. This indicates a bug in the " + "Java SDK, where a future was not completed while the channel was in use. The channel has " + "been closed, and the future will be completed to prevent any ongoing issues.", cause); executeFuture.get().completeExceptionally(cause); } else if (cause instanceof IOException) { log.debug(() -> "An I/O exception (" + cause.getMessage() + ") occurred on a channel (" + ctx.channel().id() + ") that was not in use. The channel has been closed. This is usually normal."); } else { log.warn(() -> "A non-I/O exception occurred on a channel (" + ctx.channel().id() + ") that was not in use. " + "The channel has been closed to prevent any ongoing issues.", cause); } } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { boolean channelInUse = getAttribute(ctx, ChannelAttributeKey.IN_USE).orElse(false); if (channelInUse) { ctx.fireExceptionCaught(cause); } else { ctx.close(); Optional<CompletableFuture<Void>> executeFuture = getAttribute(ctx, ChannelAttributeKey.EXECUTE_FUTURE_KEY); if (executeFuture.isPresent() && !executeFuture.get().isDone()) { log.error(() -> "An exception occurred on an channel (" + ctx.channel().id() + ") that was not in use, " + "but was associated with a future that wasn't completed. This indicates a bug in the " + "Java SDK, where a future was not completed while the channel was in use. The channel has " + "been closed, and the future will be completed to prevent any ongoing issues.", cause); executeFuture.get().completeExceptionally(cause); } else if (cause instanceof IOException) { log.debug(() -> "An I/O exception (" + cause.getMessage() + ") occurred on a channel (" + ctx.channel().id() + ") that was not in use. The channel has been closed. This is usually normal."); } else { log.warn(() -> "A non-I/O exception occurred on a channel (" + ctx.channel().id() + ") that was not in use. " + "The channel has been closed to prevent any ongoing issues.", cause); } } }
} catch (IOException deletionException) { Logger.loggerFor(ResponseTransformer.class) .error(() -> "Failed to delete destination file '" + path + "' after reading the service response " + "failed.", deletionException);