Skip to content

Commit

Permalink
Fix #114: Better error in ->clj when no kernel
Browse files Browse the repository at this point in the history
Issue: Thomas reported getting to express with no jlink-instance. This should not be possible, as wl/eval that ->clj calls checks for its presence but maybe I am missing something.

Fix: Throw a helpful error if this ever happens.

Also make terminate-kernel! more robust (in case when start failed)
  • Loading branch information
holyjak committed Sep 20, 2024
1 parent 7f668e3 commit 5fbe077
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/wolframite/base/express.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
(assert (string? s) (str "Expected '" (pr-str s) "' to be a string but is " (type s)))
;; TODO: debug log: "express string>"
(let [held-s (str "HoldComplete[" s "]")
link (proto/kernel-link jlink-instance)
link (or (proto/kernel-link jlink-instance)
(throw (IllegalStateException.
(str "Something is wrong - there is no JLink instance, which shouldn't"
" be possible. Try to stop and start Wolframite again."))))
output (io!
(locking link
(doto link
Expand Down
7 changes: 4 additions & 3 deletions src/wolframite/impl/jlink_proto_impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@
res))))
(terminate-kernel! [_this]
;; BEWARE: it is not absolutely guaranteed that the kernel will die immediately
(doto ^KernelLink @kernel-link-atom
(.terminateKernel)
(.close))
(when-let [link ^KernelLink @kernel-link-atom]
(doto link
(.terminateKernel)
(.close)))
(reset! kernel-link-atom nil))
(expr [_this primitive-or-exprs]
(make-expr primitive-or-exprs))
Expand Down

0 comments on commit 5fbe077

Please sign in to comment.