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 Pragmatic topics Top

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
New
johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
jamis
The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
HarryDeveloper
Hi @venkats, It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex> product = %Product{} %Pento....
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
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
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

DevotionGeo
I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
New
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New

Latest in PragProg

View all threads ❯