Created
October 11, 2021 20:02
-
-
Save Lambeaux/6eb14e8c3e8af43c017a64c86722054a to your computer and use it in GitHub Desktop.
Toggle to keep NodeJS ClojureScript REPL from crashing on uncaught errors
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
(defn exception-handler [err] | |
(binding [*print-fn* *print-err-fn*] | |
(println "An error occurred that otherwise would have crashed the Node process:") | |
(println err))) | |
(defn handle-all [] | |
(.on js/process "uncaughtException" exception-handler)) | |
(defn handle-none [] | |
(.removeListener js/process "uncaughtException" exception-handler)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem
To demonstrate the issue, run the following in a REPL backed by NodeJS and note the expected behavior:
The error is thrown and the REPL persists. It was able to catch the error.
The error is returned and the REPL persists. We were able to catch the error.
The channel is returned and the REPL dies. The error was thrown in an async context beyond the scope of both our try-catch and the REPL's try-catch.
Leveraging the snippet
Enable the crash protection like so:
Try the problematic eval with protection enabled:
When you're done, turn it off:
Enjoy your REPL crashing again: