Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescue from Interrupt in tailwindcss:watch #336

Merged
merged 1 commit into from Mar 7, 2024

Conversation

davidcelis
Copy link
Contributor

@davidcelis davidcelis commented Feb 23, 2024

When sending a SIGINT to end the rake tailwindcss:watch (or, for modern Procfile-based Rails applications, bin/dev) task, Ruby processes this via an Interrupt exception that can be rescued to handle gracefully tearing the process down. The tailwindcss:watch task, however, does not handle this exception, so when the task (or Rails' server via bin/dev) is terminated via the standard practice of using ^C, that exception propagates and causes tailwindcss:watch to exit 1. For some (including myself), it's also resulting in a large backtrace; this can erroneously lead developers to think something is wrong.

This patch fixes #318 by rescuing Interrupt exceptions, which I've verified in my own applications that use this gem. It didn't seem like there's any necessary teardown that needs to happen upon quitting the process, so I left the rescue clause blank except for a log line when in verbose mode. I'm happy to make any necessary changes there, however! Additionally, if that rescue should occur elsewhere (e.g. directly in exe/tailwindcss), I'm happy to move it there (I wasn't sure if that's where it belonged, as the other commands aren't meant to run indefinitely until killed).

When sending a SIGINT to end the `rake tailwindcss:watch` (or, for modern Procfile-based Rails applications, `bin/dev`) task, Ruby processes this via an `Interrupt` exception that can be rescued to handle gracefully tearing the process down. The `tailwindcss:watch` task, however, does not handle this exception, so when the task (or Rails' server via `bin/dev`) is terminated via the standard practice of using `^C`, that exception propagates and can result in a large backtrace; this can erroneously lead developers to think something is wrong.

This patch fixes rails#318 by rescuing `Interrupt` exceptions, which I've verified in my own applications that use this gem. It didn't seem like there's any necessary teardown that needs to happen upon quitting the process, so I left the `rescue` clause blank except for a log line when in verbose mode. I'm happy to make any necessary changes there, however! Additionally, if that `rescue` should occur elsewhere, like directly in `exe/tailwindcss`, I'm happy to do so there as well. I wasn't sure if that's where it belonged, however, as the other commands aren't meant to run indefinitely until killed.
@flavorjones
Copy link
Member

This seems great, thank you!

@flavorjones flavorjones merged commit ad0717f into rails:main Mar 7, 2024
23 checks passed
@flavorjones
Copy link
Member

I've also pushed a change to the CHANGELOG properly crediting you with the change. Thanks again!

@davidcelis davidcelis deleted the patch-1 branch March 7, 2024 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tailwindcss:watch terminates with exception
2 participants