Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Sep 14, 2023
1 parent 902c765 commit 94b8364
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,13 @@ else if (Types.isVncFunction(slurpOutFn)) {
future_stdout.cancel(true);
future_stderr.cancel(true);

try (WithCallStack cs = new WithCallStack(new CallFrame("sh", cmd.getMeta()))) {
//try (WithCallStack cs = new WithCallStack(new CallFrame("sh", cmd.getMeta()))) {
throw new TimeoutException(
String.format("Shell execution timeout after %ds", timeoutMillis));
}
//}
}
else if (exitCode != 0 && throwExOnFailure) {
try (WithCallStack cs = new WithCallStack(new CallFrame("sh", cmd.getMeta()))) {
//try (WithCallStack cs = new WithCallStack(new CallFrame("sh", cmd.getMeta()))) {
throw new ShellException(
String.format(
"Shell execution failed: (sh %s). Exit code: %d",
Expand All @@ -438,7 +438,7 @@ else if (exitCode != 0 && throwExOnFailure) {
.collect(Collectors.joining(" ")),
exitCode),
exitCode);
}
//}
}
else {
return VncHashMap.of(
Expand All @@ -451,9 +451,12 @@ else if (exitCode != 0 && throwExOnFailure) {
catch(ShellException ex) {
throw ex;
}
catch(TimeoutException ex) {
throw ex;
}
catch(Exception ex) {
try (WithCallStack cs = new WithCallStack(new CallFrame("sh", cmd))) {
throw new VncException(
throw new ShellException(
String.format(
"Shell execution processing failed: (sh %s)",
cmd.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.junit.jupiter.api.Test;

import com.github.jlangch.venice.ShellException;
import com.github.jlangch.venice.TimeoutException;
import com.github.jlangch.venice.Venice;
import com.github.jlangch.venice.VncException;
import com.github.jlangch.venice.impl.util.junit.EnableOnMacOrLinux;


Expand All @@ -46,6 +46,17 @@ public void test_shell() {
assertEquals(0L, result.get("exit"));
}


@Test
@EnableOnMacOrLinux
public void test_shell_exit_code() {
final Venice venice = new Venice();

final String script = "(:exit (sh \"/bin/sh\" \"-c\" \"exit 2\"))";

assertEquals(2L, venice.eval(script));
}

@Test
@EnableOnMacOrLinux
public void test_shell_with_dir_1() {
Expand Down Expand Up @@ -132,7 +143,7 @@ public void test_shell_stdout_timeout() {
" \"-c\" \"for i in {1..3}; do sleep 1; echo \\\"Hello $i\\\"; done\" \n" +
" :timeout 1500))";

assertThrows(VncException.class, () -> venice.eval(script));
assertThrows(TimeoutException.class, () -> venice.eval(script));
}

@Test
Expand Down Expand Up @@ -178,6 +189,6 @@ public void test_shell_stdout_fn_timeout() {
" :err-fn println \n" +
" :timeout 1500))";

assertThrows(VncException.class, () -> venice.eval(script));
assertThrows(TimeoutException.class, () -> venice.eval(script));
}
}

0 comments on commit 94b8364

Please sign in to comment.