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

hook: React to commands failures #2835

Open
jhermann opened this issue Mar 10, 2018 · 3 comments
Open

hook: React to commands failures #2835

jhermann opened this issue Mar 10, 2018 · 3 comments
Assignees
Labels
feature features we would like to implement

Comments

@jhermann
Copy link
Contributor

jhermann commented Mar 10, 2018

I noticed that hook.py uses subprocess.Popen(command_pieces).wait() (BTW, why not subprocess.call), and does not check the return code (you ignore the wait result). It also might be you thought this code does what check_call does (namely, throw on non-OK exit). Right now, your exception handler is only triggered when the command cannot be found.

An improvement would be to log a warning on non-OK exit code, and allow failing commands to exit the beets process. Example:

hook:
  hooks:
    - event: import
      command: chmod -R go+rX "{lib.directory}"
      on_error: abort

Choices for on_error would be abort, ignore (the default), log, skip_album, and skip_item.

skip_* would depend on the event, e.g. skip an album import if the command fails.

@sampsyo sampsyo added the feature features we would like to implement label Mar 11, 2018
@sampsyo
Copy link
Member

sampsyo commented Mar 11, 2018

Sounds good!

I’m not aware of a reason why that code doesn’t use the higher-level wrappers in subprocess. That would be nice to fix too.

@jackwilsdon
Copy link
Member

I wouldn't mind looking into this, however I'm not quite sure how the skip functionality would work. Do you have any specific events in mind for the skip operations @jhermann? The only tasks I can see which it would really work for are import_task_created and maybe a few of the other import_task_* events.

Similarly, how would abort work? Would it just throw an exception to force beets to exit? It seems like most events don't provide any cancellation functionality, so that looks like it might be the only way to do it.

Would ignore stop logging errors? If so then we should probably default to log which is what we do right now.

@anarcat
Copy link
Contributor

anarcat commented Jan 13, 2022

Do you have any specific events in mind for the skip operations @jhermann? The only tasks I can see which it would really work for are import_task_created and maybe a few of the other import_task_* events.

old issue, but yeah, this would be relevant to avoid messing around with files that are handled by another manager, say a torrent client (#2617).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature features we would like to implement
Projects
None yet
Development

No branches or pull requests

4 participants