Skip to content

Commit

Permalink
Merge pull request #140 from jenkinsci/fix/SUP-1105_report_to_utf8
Browse files Browse the repository at this point in the history
fix: catch exception when converting report to utf-8
  • Loading branch information
PeterSchafer committed Jun 28, 2023
2 parents a23bde5 + 1ab0a1a commit 112ca89
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main/java/io/snyk/jenkins/SnykToHTML.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Map;
import java.nio.charset.MalformedInputException;

import static io.snyk.jenkins.Utils.getURLSafeDateTime;
import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down Expand Up @@ -58,19 +59,23 @@ public static FilePath generateReport(
.join();
}

String stdout = stdoutPath.readToString();

if (LOG.isTraceEnabled()) {
LOG.trace("snyk-to-html command: {}", command);
LOG.trace("snyk-to-html exit code: {}", exitCode);
LOG.trace("snyk-to-html stdout: {}", stdout);
}

if (exitCode != 0) {
throw new RuntimeException("Exited with non-zero exit code. (Exit Code: " + exitCode + ")");
}

stdoutPath.write(stdout, UTF_8.name());
try {
String stdout = stdoutPath.readToString();

if (LOG.isTraceEnabled()) {
LOG.trace("snyk-to-html command: {}", command);
LOG.trace("snyk-to-html exit code: {}", exitCode);
LOG.trace("snyk-to-html stdout: {}", stdout);
}

stdoutPath.write(stdout, UTF_8.name());
} catch(MalformedInputException e) {
logger.println("Couldn't convert report to UTF-8.");
}

return stdoutPath;
} catch (IOException | InterruptedException | RuntimeException ex) {
Expand Down

0 comments on commit 112ca89

Please sign in to comment.