neodoc npm模块抛出的错误会使ClojureScript(但不是Node.js)出现问题时。
$ java -cp cljs.jar cljs.main --repl-env node
ClojureScript 1.10.758
cljs.user=> (def neodoc (js/require "neodoc"))
#'cljs.user/neodoc
cljs.user=> (.run neodoc "Usage:\n foo" (clj->js {:argv []}))
#js {}
cljs.user=> (.run neodoc "Usage:\n foo" (clj->js {:argv ["bar"] :dontExit true}))
Execution error () at (<cljs repl>:1).
null
cljs.user=> (try (.run neodoc "Usage:\n foo" (clj->js {:argv ["bar"] :dontExit true})) (catch :default e (prn :e e)))
Execution error (TypeError) at (<cljs repl>:1).
Function.prototype.toString requires that 'this' be a Function
这在node中工作(尽管抛出的对象很奇怪)
Welcome to Node.js v16.13.2.
Type ".help" for more information.
> neodoc = require("neodoc")
{
run: [Function: run],
parse: [Function: parse],
default: { run: [Function: run], parse: [Function: parse] }
}
> neodoc.run("Usage:\n foo", {argv: ["bar"], dontExit: true})
Uncaught:
Function {
message: 'foo: unknown command bar\n' +
'Usage:\n' +
' foo\n' +
'See foo -h/--help for more information',
payload: {}
}
> try { neodoc.run("Usage:\n foo", {argv: ["bar"], dontExit: true}) } catch (e) { console.log("e:", e) }
e: Function {
message: 'foo: unknown command bar\n' +
'Usage:\n' +
' foo\n' +
'See foo -h/--help for more information',
payload: {}
}
undefined