Skip to content

Commit

Permalink
Merge pull request #232 from StefanSpieker/unsignedInt
Browse files Browse the repository at this point in the history
Handle unsigned int errorcodes more gracefully in Windows Batch
  • Loading branch information
jglick authored Sep 13, 2024
2 parents 32f60c3 + 07ea6a5 commit 2a8a4b7
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) {
LOGGER.warning("ErrorCode greater than max integer detected, limited to max value");
value = Integer.MAX_VALUE;
}
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 2a8a4b7

Please sign in to comment.