A Sound Solution: Alerting Dev Server Failures

tomas223

Tomas Hornak

Posted on January 26, 2024

A Sound Solution: Alerting Dev Server Failures

During my recent work developing a web app with NextJs 13+, I came across a sly problem - silent (dev) server (with ZERO status code). Picture this: you're engrossed in code, cranking out new features, but nothing seems to change. After what feels like forever in developer's time (aka two minutes), you realize your dev server had crashed without you noticing.

But don't worry, because I found a way to stay ahead. Say hello to this lifesaving command:

xdev:
    @trap 'say "This is outrageous"' ERR \
        ; script -q /dev/null pnpm run dev:dashboard | tee /dev/tty \
        | grep --line-buffered -q "JavaScript heap out of memory" && say "Ooops" \
        ; stty sane
Enter fullscreen mode Exit fullscreen mode

Let's break it down:

  • trap 'say "This is outrageous"' ERR this part instructs the system to say "This is outrageous" whenever an normal error occurs.
  • script -q /dev/null npm run dev | tee /dev/tty run dev server with npm run dev, pipe the output using script command to keep the colors in an stdout
  • grep --line-buffered -q "JavaScript heap out of memory" && say "Ooops" if the error message "JavaScript heap out of memory" appears, it triggers the system to say "Ooops".
  • stty sane reset the terminal settings if they've became garbled

In essence, this command provides an sound alert when your dev server fails, saving you precious minutes of confusion.

To run it simply type:

make xdev
Enter fullscreen mode Exit fullscreen mode

Change "grepped" error message that triggers voice message "Oops" according your dev command or update sound to something funnier 8-)

Although developed for macOS, it should be easily transferable to Linux with one or two tweaks.

With this command, silent dev server failures will be a thing of the past. You can focus on conquering NextJs or any other framework, knowing an audible alert has got your back.

Have you encountered similar baffling situations in your development journey? What were your unique solutions?

💖 💪 🙅 🚩
tomas223
Tomas Hornak

Posted on January 26, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related