A Clojure/Swank `break` exits the enclosing Leiningen process--why?
I was debugging my Clojure program, Infocard Workbench, when I got a truly unexpected error: A (swank.core/break)
in a function caused an error to the CLI window that aborted execution, even though the running program, (-main)
, was called by the Clojure/Swank REPL. When I commented out the break statement, the program behaved normally. Why did I get an error from the leiningen process that created the REPL and not from the SWANK REPL itself?
In case it matters, the program uses the following libraries: Seesaw (Swing UI); Piccolo2D (Swing 2D-graphics); Sedna (XML database with XQuery access).
The stack trace is below. Lines that begin " GW COMMENT >>> " are comment lines I've added and are not part of the trace.
--- BEGIN cli window output ---
generic-sh-d: field-text is
GW COMMENT >>> Here, I'm in the menu handler for a file-open operation (Seesaw)
shortname-hdlr: filename is t
shortname-handler, inside 2nd 'let'
reached display-file-icards
GW COMMENT >>> Here, I'm printing out actual XQueries to the Sedna database.
declare default element namespace 'http://infoml.org/infomlFile'; for $base in doc('t', 'daily')/infomlFile/infoml[position() != 1] return $base/@cardId/string()
unified-load, before
declare default element namespace 'http://infoml.org/infomlFile';
for $base in collection('daily')/infomlFile/infoml[@cardId = 'gw667_110929221548137']
return ($base/data/title/string(), $base/data/content/string(), $base/selectors/tag/string())
GW COMMENT >>> More XQueries; the "AFTER" indicates the query completed w/o crashing
unified-load, AFTER
unified-load, before
declare default element namespace 'http://infoml.org/infomlFile';
for $base in collection('daily')/infomlFile/infoml[@cardId = 'gw667_110929221638791']
return ($base/data/title/string(), $base/data/content/string(), $base/selectors/tag/string())
unified-load, AFTER
GW COMMENT >>> omitted several before/AFTER pairs; all were successful
GW COMMENT >>> Here's the actual error; note the namespace, swank.core.connection
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Var swank.core.connection/*current-connection* is unbound.
at clojure.lang.Var.deref(Var.java:142)
at clojure.lang.Var.get(Var.java:133)
at swank.core$send_to_emacs.invoke(core.clj:76)
at swank.core$sldb_loop.invoke(core.clj:203)
at swank.core$invoke_debugger.invoke(core.clj:214)
at infwb.sedna$display_file_icards.invoke(NO_SOURCE_FILE:1)
at infwb.misc_dialogs$shortname_handler.invoke(misc_dialogs.clj:76)
at infwb.core$make_app$open_h__3812.invoke(core.clj:37)
at seesaw.action$action$fn__386.invoke(action.clj:74)
at seesaw.action.proxy$javax.swing.AbstractAction$0.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
unified-load, AFTER
display-file-icards: exited let-bindings
at javax.开发者_运维问答swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:95)
at java.awt.MenuItem.processActionEvent(MenuItem.java:627)
at java.awt.MenuItem.processEvent(MenuItem.java:586)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:337)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:325)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:682)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:638)
at java.awt.EventQueue$1.run(EventQueue.java:636)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:652)
at java.awt.EventQueue$2.run(EventQueue.java:650)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:649)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
--- END cli window output ---
Here's the function containing the break
statement:
(defn display-file-icards ; NEW API 111002
""
[shortname coll-name layer-name]
(println "reached display-file-icards")
(let [icard-seq (get-file-icards shortname coll-name)
slip-seq (doall (map unified-load icard-seq))]
(println "display-file-icards: exited let-bindings")
(swank.core/break)
(display-seq slip-seq layer-name)))
Recalling the error message:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException:
Var swank.core.connection/*current-connection* is unbound.
I can't see how *current-connection*
is connected to the execution of a Swank break
message. My program does have a symbol named *current-connection*
, but it's in namespace infwb.sedna
, which is different from the namespace my REPL is running in, which is infwb.core
.
I can post more Clojure source code if anybody wants it. Thanks for taking the time to think about this.
Not that I have the remotest clue of whether this will help, but I do notice that swank-clojure is deprecated in favor of nrepl. Perhaps nrepl works?
I added my nrepl support to emacs via the melpa repository, and "jack in" via M-x nrepl-jack-in
.
The relevant bits of my .emacs.d/init.el look like (this will work on Emacs24 and newer):
(require 'package)
(setq package-user-dir "~/.emacs.d/elpa/")
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
(defvar my-packages '(melpa
exec-path-from-shell
starter-kit
starter-kit-lisp
starter-kit-bindings
ess
clojure-mode
clojure-test-mode
paredit
ac-nrepl
nrepl
auto-complete
ac-nrepl
twilight-theme
auctex)
"A list of packages to ensure are installed at launch.")
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p)))
EDIT: Oops, just noticed the year on this one. I'm guessing this probably isn't an issue for you anymore.
精彩评论