poverholt

poverholt

Web Development with Clojure, Third Edition: correct reference code (page 116)

In general, how do I correctly find the reference code that matches each book topic?

More specifically, I am having problems around page 116 testing that the code still works after setting up shadow-cljs. I tried using the reference code called “guestbook-shadow” and still had the same problems. Maybe I am using the wrong reference code. The problems I see are…

  • I don’t always see the “WebSocket connected!” in the browser. I have not figured out yet exactly when this happens.
  • GET /api/messages response is always 500 “Internal Server Error”
  • The page never gets passed “Loading Messages…”
  • Sometimes I get this error about invalid gy flags in xregexp.
  • I get some error about protocol_mask partition.
  • The browser console shows errors about formatters not being installed and another about custom formatters not being rendered.
  • On the positive side, the browser console reports App initilized and components mounted and shadow-cljs ready.

How do I debug this? A server-side unit test of get-messages responds with 200, so I think the problem is in middleware or the websocket config. I was hoping the reference code would help, but assuming I have the right one, it is the same, with exception of some SQL files.

I am enjoying the book very much & looking forward to getting past this hump. Thanks for your hard work.

Regards,
Pete

Most Liked

svmbrown

svmbrown

Author of Web Development with Clojure

You can find the reference code here under the “Resources” section.

The “WebSocket Connected” message not appearing is likely due to shadow-cljs being inactive or still compiling. You can try getting more info from the browser console, or check the CLI output for a message that looks like [:app] Build Completed. (...)

The 500 from /api/messages could be plenty of things. Validating the get-messages function is a good start, that means it’s likely an issue with the route itself. Check the logs for an error, and if that’s not descriptive, add a log statement at the very beginning of your handler fn to make sure you enter it. If not, it’s likely an issue with the :parameters or :responses validation, but it could be another route issue. If you do get the log statement, wrap the handler body in a try/catch and log the error before re-throwing to get more info. Sometimes the error can get obfuscated by the middleware stack.

The page never getting past “loading messages…” is a result of the 500 most likely, since they’re failing to load.

The gy flags in xregexp is a version issue. Try bumping the version and removing core-js dependency.

I am not sure what the protocol_mask partition issue is, so that would need some further investigation. Sorry I can’t be helpful there. Try seeking out help from shadow-cljs documentation or open an issue on the shadow-cljs github repository if you can’t resolve it. https://github.com/thheller/shadow-cljs

The formatters sounds like an issue with cljs-devtools chrome plugin. It shouldn’t be an issue with the application itself.

Good luck with the debugging. Share your logs and relevant code if you’re still stuck.

Glad to hear you’re enjoying the book so far, thanks for reading!

poverholt

poverholt

Thanks for such a detailed response Scot! It really helped me get back on track. Everything is behaving as expected now.

With the try/catch suggestion, I figured out the database was corrupted or missing. Once re-generated, I was at least getting some data back. I couldn’t successfully regenerate just by using the repl and commands in env/dev/clj/user. It seems I had to use the OS to delete the DB files. Is there a simple and reliable way to regenerate the DB?

Making sure my project.clj dependencies, especially ClojureScript, was updated to match the sample code for the shadow section helped get rid of several errors. Switching from Firefox to Chrome and using Web Dev settings under “console” to "enable custom formatters helped too. I often get burned by cached web pages, but I am starting to remember to look to that first when I see unexpected behavior. Can I use any browser or is Chrome required during development?

I am looking forward to the re-frame work. Thanks again, Pete.

svmbrown

svmbrown

Author of Web Development with Clojure

Glad to hear you got things sorted out!

You can use any browser, but chrome/chromium has a slight edge with support for devtools. My workflow tends to be to get stuff working in chromium and then validate in firefox once things are fairly complete.

With regards to regenerating the DB from the REPL, it largely depends on what went wrong. luminus-migrations does provide rollback and reset functions, but that will only be as good as your migrations are. If you’ve made an error in writing a migration file, it won’t help. I’d recommend using SQL (either from your favourite client or from the REPL) to inspect the structure of your tables and compare against what you expect.

Happy Hacking!

Scot

Popular Prag Prog topics Top

jon
Some minor things in the paper edition that says “3 2020” on the title page verso, not mentioned in the book’s errata online: p. 186 But...
New
New
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
leonW
I ran this command after installing the sample application: $ cards add do something --owner Brian And got a file not found error: Fil...
New
brunogirin
When I run the coverage example to report on missing lines, I get: pytest --cov=cards --report=term-missing ch7 ERROR: usage: pytest [op...
New
AufHe
I’m a newbie to Rails 7 and have hit an issue with the bin/Dev script mentioned on pages 112-113. Iteration A1 - Seeing the list of prod...
New
andreheijstek
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New
dachristenson
I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity...
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
New
foxtrottwist
Here’s our thread for the Keyboardio Atreus. It is a mechanical keyboard based on and a slight update of the original Atreus (Keyboardio ...
New
AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
New
Exadra37
I am a Linux user since 2012, more or less, and I always use Ubuntu on my computers, and my last 2 laptops have been used Thinkpads, wher...
New
AstonJ
Biggest jackpot ever apparently! :upside_down_face: I don’t (usually) gamble/play the lottery, but working on a program to predict the...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New

Latest in PragProg

View all threads ❯