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

Return error code != 0 for errors during verdi import #4430

Closed
CasperWA opened this issue Oct 8, 2020 · 6 comments · Fixed by #4532
Closed

Return error code != 0 for errors during verdi import #4430

CasperWA opened this issue Oct 8, 2020 · 6 comments · Fixed by #4532

Comments

@CasperWA
Copy link
Contributor

CasperWA commented Oct 8, 2020

Describe the bug

If a migration of an export archive fails, the return code is still 0.

Steps to reproduce

Use verdi export migrate with an invalid export archive.
Check return code in the terminal afterwards ($ echo $?).

Expected behavior

For any reporting within verdi, if ERROR: is printed/returned, the return code should not be 0.

Your environment

  • Operating system: Ubuntu 18.04 LTS in WSL 2.0 on Windows 10.
  • Python version: 3.7
  • aiida-core version: 1.4.2

Additional context

This was found by @asle85 during automatic migration of archives for Materials Cloud via Ansible playbooks.

@CasperWA
Copy link
Contributor Author

CasperWA commented Oct 8, 2020

It seems there are two different functions for returning an error from verdi. One can either use aiida.cmdline.utils.echo.echo_error or aiida.cmdline.utils.echo.echo_critical. echo_critical will exit with return code 1, while echo_error will return with code 0. Is this intended @ltalirz @giovannipizzi @sphuber?

@sphuber
Copy link
Contributor

sphuber commented Oct 8, 2020

This is the intended behavior yes. If the command should fail, one should use echo_critical. If you need to continue the command, you can use echo_error but than return non-zero exit value yourself.

@CasperWA CasperWA changed the title Return error code != 0 for verdi echo error Return error code != 0 for errors during verdi import Oct 8, 2020
@ltalirz ltalirz closed this as completed Oct 8, 2020
@ltalirz
Copy link
Member

ltalirz commented Oct 8, 2020

Closing this - feel free to ask further questions if anything is unclear

@CasperWA
Copy link
Contributor Author

CasperWA commented Oct 8, 2020

I have repurposed this issue to return a non-zero error code in verdi import if an error occurs.

@ltalirz
Copy link
Member

ltalirz commented Oct 29, 2020

@chrisjsewell After the refactoring, is verdi import now returning a non-zero exit code for all failures?

@chrisjsewell chrisjsewell linked a pull request Oct 29, 2020 that will close this issue
@chrisjsewell
Copy link
Member

Marking this as closed by #4532, and we can double-check that this is actually the case

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