How can I create a custom failure message for a task? #2854
-
|
How can I create a custom failure message for a task? As a simplified example, let's say I'm creating a task that checks for uncommitted changes in a repo. My task looks like this: Functionally, this works fine. If there are uncommitted changes in the repo, the task fails like so: However, I find the failure message in this case to be a little bit opaque; I don't believe it's clear to the user what specific conditions caused this task to fail. I would prefer for the output to say something along the lines of "You appear to have uncommitted changes in your repository. Please commit your changes and try again." Is there a Taskfile-idiomatic way of printing custom output upon task failure? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
Aha, I think I found a workable solution. It feels a little clunky, but it seems to work. I'm happy to hear other suggestions as well. Output: |
Beta Was this translation helpful? Give feedback.
-
|
Ahh, here we go. This is much better. The combo of Output: |
Beta Was this translation helpful? Give feedback.
-
|
You can use preconditions : https://taskfile.dev/docs/guide#using-programmatic-checks-to-cancel-the-execution-of-a-task-and-its-dependencies with a proper msg |
Beta Was this translation helpful? Give feedback.
You can use preconditions : https://taskfile.dev/docs/guide#using-programmatic-checks-to-cancel-the-execution-of-a-task-and-its-dependencies with a proper msg