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

task error handling #3525

Open
jdx opened this issue Dec 13, 2024 · 6 comments
Open

task error handling #3525

jdx opened this issue Dec 13, 2024 · 6 comments

Comments

@jdx
Copy link
Owner

jdx commented Dec 13, 2024

there should be some kind of error handling to execute something when a task fails, perhaps to cancel the error somehow. My use-case for this is I have a bunch of tasks that run and leave the project in an inconsistent state when they fail because it's all running in parallel. There is a specific task that—if failed—I'd like it to reset the contents of a specific file.

Noodling on this:

[tasks.render]
run = "node build-something.js > output"
on_failure = "git checkout output"

I don't personally need to cancel the error—though I feel like with this sort of thing that's probably going to be behavior someone wants—especially if I call this "error handling".

Maybe we could make that an optional setting:

[tasks.render]
run = "node build-something.js > output"
on_failure = {run = "git checkout output", cancel_error = true}

what do other task managers do?

@jdx
Copy link
Owner Author

jdx commented Dec 16, 2024

perhaps a better way to name this would be "cleanup" and not worry about catching errors

@acesyde
Copy link
Contributor

acesyde commented Dec 20, 2024

Maybe add the ability to only trigger the failure case on a specific exit code ?

@jdx
Copy link
Owner Author

jdx commented Dec 20, 2024

I was going to pass the status code as an env var

@reteps
Copy link

reteps commented Dec 20, 2024

The status code should be available in $? in my opinion for use in cleanup.

@jdx
Copy link
Owner Author

jdx commented Dec 20, 2024

setting that before a script runs is complicated and something that would have to be unique depending on which shell is being used. Imagine a handler being written in python, for example.

@reteps
Copy link

reteps commented Dec 20, 2024

Ah, you are correct. TIL: https://stackoverflow.com/a/26627346

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants