Skip to content

Commit

Permalink
handle unsigned int errorcodes more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanSpieker committed Sep 13, 2024
1 parent cc2bd57 commit 07ea6a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,12 @@ public Integer invoke(File f, VirtualChannel channel) throws IOException, Interr
return null;
} else {
try {
return Integer.valueOf(text);
long value = Long.parseLong(text);
if (value > Integer.MAX_VALUE) {

Check warning on line 397 in src/main/java/org/jenkinsci/plugins/durabletask/FileMonitoringTask.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 397 is only partially covered, one branch is missing
LOGGER.warning("ErrorCode greater than max integer detected, limited to max value");
value = Integer.MAX_VALUE;

Check warning on line 399 in src/main/java/org/jenkinsci/plugins/durabletask/FileMonitoringTask.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 398-399 are not covered by tests
}
return (Integer) (int) value;
} catch (NumberFormatException x) {
throw new IOException("corrupted content in " + f + ": " + x, x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ private void testWithPath(String path) throws Exception {
c.cleanup(ws);
}

@Test public void exitCommandUnsignedInt() throws Exception {
Controller c = new WindowsBatchScript("echo hello world\r\nexit 3221225477").launch(new EnvVars(), ws, launcher, listener);
awaitCompletion(c);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
c.writeLog(ws, baos);
if (enableBinary) {
assertEquals(Integer.valueOf(Integer.MAX_VALUE), c.exitStatus(ws, launcher, listener));
} else {
assertEquals(Integer.valueOf(-1073741819), c.exitStatus(ws, launcher, listener));
}

String log = baos.toString();
assertTrue(log, log.contains("hello world"));
c.cleanup(ws);
}

@Test public void exitBCommandAfterError() throws Exception {
Controller c = new WindowsBatchScript("cmd /c exit 42\r\nexit /b").launch(new EnvVars(), ws, launcher, listener);
awaitCompletion(c);
Expand Down

0 comments on commit 07ea6a5

Please sign in to comment.