Skip to content

Commit

Permalink
Fix Exceptions are not handled on premain (#873)
Browse files Browse the repository at this point in the history
* Fix Exceptions are not handled on premain

Signed-off-by: guhanjie <[email protected]>
  • Loading branch information
guhanjie authored Aug 17, 2023
1 parent 18d94bd commit 34e9841
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ public static void premain(String agentArgument, Instrumentation instrumentation
CollectorRegistry.defaultRegistry,
true,
new File(config.file));
} catch (ConfigurationException e) {
System.err.println("Configuration Exception : " + e.getMessage());
System.exit(1);
} catch (IllegalArgumentException e) {
System.err.println(
"Usage: -javaagent:/path/to/JavaAgent.jar=[host:]<port>:<yaml configuration"
+ " file> "
+ e.getMessage());
} catch (Throwable t) {
synchronized (System.err) {
System.err.println("Failed to start Prometheus JMX Exporter");
System.err.println();
t.printStackTrace();
System.err.println();
System.err.println("Prometheus JMX Exporter exiting");
System.err.flush();
}
System.exit(1);
}
}
Expand All @@ -88,7 +89,9 @@ public static Config parseConfig(String args, String ifc) {

Matcher matcher = pattern.matcher(args);
if (!matcher.matches()) {
throw new IllegalArgumentException("Malformed arguments - " + args);
System.err.println(
"Usage: -javaagent:/path/to/JavaAgent.jar=[host:]<port>:<yaml configuration file> ");
throw new ConfigurationException("Malformed arguments - " + args);
}

String givenHost = matcher.group(1);
Expand Down

0 comments on commit 34e9841

Please sign in to comment.