copier icon indicating copy to clipboard operation
copier copied to clipboard

Show clean failure messages for tasks that exit with non-zero code

Open dusktreader opened this issue 7 months ago • 1 comments

Actual Situation

I've built a template (requires --trust) that includes executing some github CLI commands in the tasks. Thus, the first task is to run gh auth status | grep {{ github_account }} to make sure that the user is logged in and using the account they declared in the questions. This works great as a check. However, it results in an ugly stack trace from the copier internals and the final exception message is 'gh auth status' returned non-zero exit status. It's not very obvious for anyone who didn't write the template what the problem actually is and how it should be resolved.

Desired Situation

It would be very nice if this stack trace wasn't printed as it doesn't really provide any useful insight. It's just subprocess() raising an exception due to a non-zero exit status.

It would be even nicer if the task could be configured with a nice, friendly failure message for the user. In my case, I would love to print something like: "Please log in to github as {{ github_account }} by running gh auth login"

Proposed solution

This would be a simple as adding an additional property to a task called failure_message. Then, you could catch subprocess.CalledcProcessError and print the failure message instead of just letting the exception halt the program.

dusktreader avatar Apr 14 '25 03:04 dusktreader

Thanks for the request @dusktreader. It makes sense to me: as you said, the traceback of subprocess errors is probably never useful in our case (and always the same).

pawamoy avatar Apr 14 '25 22:04 pawamoy