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

Where Next?

Popular Pragmatic Bookshelf topics Top

belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
New
mert
AWDWR 7, page 152, page 153: Hello everyone, I’m a little bit lost on the hotwire part. I didn’t fully understand it. On page 152 @rub...
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
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New
gorkaio
root_layout: {PentoWeb.LayoutView, :root}, This results in the following following error: no “root” html template defined for PentoWeb...
New

Other popular topics Top

AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
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
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New
New

Sub Categories: