Skip to content

Commit

Permalink
Merge pull request #738 from null-a/fix-readable-errors
Browse files Browse the repository at this point in the history
Make error handling work when resuming trampoline.
  • Loading branch information
stuhlmueller committed Dec 20, 2016
2 parents ebab602 + d9e35ad commit 0db8ab1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
6 changes: 5 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ function prepare(codeAndAssets, k, options) {
var currentAddress = {value: undefined};
var defaultHandler = function(error) {
errors.extendError(error, codeAndAssets, currentAddress);
// Trigger clean-up. When using the mongo store, the process won't
// exit until the connection is closed.
cleanup(_.identity);
throw error;
};
var allErrorHandlers = [defaultHandler].concat(options.errorHandlers);
Expand All @@ -232,8 +235,9 @@ function prepare(codeAndAssets, k, options) {

// Before the program finishes, we tell the param store to finish up
// gracefully (e.g., shutting down a connection to a remote store).
var cleanup = params.stop;
var finish = function(s, x) {
return params.stop(function() {
return cleanup(function() {
return k(s, x);
});
};
Expand Down
43 changes: 22 additions & 21 deletions webppl
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,29 @@ function run(code, packages, verbose, debug, programFile) {
pkg.headers.forEach(webppl.requireHeader);
});

try {
webppl.run(code, topK, {
bundles: webppl.parsePackageCode(packages, verbose),
filename: programFile,
verbose: verbose,
debug: debug
});
} catch (error) {
if (error instanceof Error && error.wpplRuntimeError) {
try {
var stack = errors.recoverStack(error, parseV8);
showError(error, stack, programFile, debug);
process.exitCode = 1;
} catch (e) {
// If we fail to generate a readable error message re-throw
// the original error.
throw error;
webppl.run(code, topK, {
bundles: webppl.parsePackageCode(packages, verbose),
filename: programFile,
verbose: verbose,
debug: debug,
errorHandlers: [
function(error) {
if (error instanceof Error && error.wpplRuntimeError) {
try {
var stack = errors.recoverStack(error, parseV8);
showError(error, stack, programFile, debug);
process.exitCode = 1;
} catch (e) {
// If we fail to generate a readable error message re-throw
// the original error.
throw error;
}
} else {
throw error;
}
}
} else {
throw error;
}
}
]
});
}

var lines = function(ar) {
Expand Down

0 comments on commit 0db8ab1

Please sign in to comment.