-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return error instead of killing process
- Loading branch information
Showing
2 changed files
with
25 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
import exec from 'k6/x/exec'; | ||
|
||
export default function () { | ||
// Basic example: | ||
console.log(exec.command("date")); | ||
|
||
// With custom error handling: | ||
try { | ||
var output = exec.command("ls",["-a", "NO_SUCH_DIR"], { | ||
"continue_on_error": true | ||
}); | ||
} catch (e) { | ||
console.log("ERROR: " + e); | ||
if (e.value && e.value.stderr) { | ||
console.log("STDERR: " + String.fromCharCode.apply(null, e.value.stderr)) | ||
} | ||
} | ||
|
||
// without error handling the test will stop when the following command fails | ||
console.log(exec.command("ls",["-a","-l"], { | ||
"dir": "sub-directory" // optional directory in which the command has to be run | ||
})); | ||
} | ||
|
||
console.log("this message will not be printed") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters