learningclojurescript / code-examples

Project code from Learning ClojureScript
http://www.learningclojurescript.com
21 stars 5 forks source link

`piggieback_project` WebSocket connection error #2

Open xiongtx opened 7 years ago

xiongtx commented 7 years ago

Expected behavior

The piggieback_project should successfully connect to a REPL.

Actual behavior

Following the instructions in the book results in a WebSocket error.

Steps to reproduce the problem

  1. Clone the repo
  2. cd to the piggieback project
  3. lein repl
  4. Run the following per book's instructions:
(require 'cljs.build.api)
(cljs.build.api/build "src"
                      {:main 'piggieback-project.core
                       :output-to "out/main.js"
                       :verbose true})
(require 'cljs.repl.browser)

(cemerick.piggieback/cljs-repl (cljs.repl.browser/repl-env))
  1. See that there is a WebSocket error.

Backtraces if necessary (M-x toggle-debug-on-error)

There seems to be no build-in way to save stack traces from Chrome console logs, so I did the best I could:

VM611:35WebSocket connection to 'ws://localhost:9001/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
WrappedWebSocket                                                   @ VM611:35
goog.net.WebSocket.open                                            @ websocket.js:283
goog.net.WebSocket.clojure$browser$net$IConnection$connect$arity$3 @ websocket.cljs:35
clojure.browser.net.connect.cljs$core$IFn$_invoke$arity$3          @ net.cljs:34
clojure$browser$net$connect                                        @ net.cljs:30
goog.net.WebSocket.clojure$browser$net$IConnection$connect$arity$2 @ websocket.cljs:33
clojure.browser.net.connect.cljs$core$IFn$_invoke$arity$2          @ net.cljs:33
clojure$browser$net$connect                                        @ net.cljs:30
weasel.repl.connect.cljs$core$IFn$_invoke$arity$variadic           @ repl.cljs:88
weasel$repl$connect                                                @ repl.cljs:56
(anonymous function)                                               @ core.cljs:5

WebSocket connection to 'ws://localhost:9001/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
WebSocket error goog.net.WebSocket.ErrorEventcurrentTarget: goog.net.WebSocketdata: undefineddefaultPrevented: falsepropagationStopped_: falsereturnValue_: truetarget: goog.net.WebSockettype: "error_1"__proto__: goog.events.Event
Closed Websocket REPL connection

Environment & version information

Google Chrome:

Version 54.0.2840.71 (64-bit)

Leiningen

Leiningen 2.7.1 on Java 1.8.0_111 OpenJDK 64-Bit Server VM

Shell

GNOME Terminal 3.20.2

OS

Fedora 24
venantius commented 7 years ago

Hey @xiongtx, thanks for filing this. I've been able to verify and reproduce that this is a bug.

@turbopape was the original author of this chapter so I'm not sure how to account for the bug, but what I can say is that (a) this doesn't seem to work because it doesn't actually start the websocket server, it just starts a general file server and (b) this section isn't super important in the context of the larger chapter or book (in other words, in two pages you'll get a different REPL connection technique that does work, and most of the rest of the book relies on Figwheel for a REPL instead of Weasel and Piggieback).

Please accept my apologies for the bug being there and the inconvenience :(

xiongtx commented 7 years ago

So you don't know how to fix it? Maybe @turbopape has a better idea?