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

Rustic returns exit code 0 when errors occur #927

Closed
florensie opened this issue Nov 5, 2023 · 8 comments · Fixed by #1220
Closed

Rustic returns exit code 0 when errors occur #927

florensie opened this issue Nov 5, 2023 · 8 comments · Fixed by #1220
Labels
A-cli Area: `rustic` command line interface C-enhancement Category: New feature or request C-upstream Category: Issue for a dependency, will be fixed upstream P-high Priority: High, to be fixed at a higher priority

Comments

@florensie
Copy link

For automation tools it would be useful if a non-zero exit code is returned when the repository is not initialized. In fact this is exactly what Restic suggests you do in their scripting documentation, but it doesn't work for Rustic:

/app # restic -r test cat config
Fatal: unable to open config file: stat test/config: no such file or directory
Is there a repository at the following location?
test
/app # echo $?
1
/app # rustic -r test cat config
using no config file, none of these exist: /root/.config/rustic/rustic.toml, /etc/rustic/rustic.toml, ./rustic.toml
error: No repository config file found. Is there a repo at local:test?
/app # echo $?
0

There may be more instances where exit codes are not properly implemented, but this is all I have tested as of now.

@github-actions github-actions bot added the S-triage Status: Waiting for a maintainer to triage this issue/PR label Nov 5, 2023
@aawsome
Copy link
Member

aawsome commented Nov 5, 2023

@florensie Thanks for opening the issue - in fact rustic doesn't return exit codes if something fails. This should be enhanced.
A workaround is to grep the output for error messages or warnings in your scripts.

About the exit code when the repository is not initialized: What is your specific use case? If it is to check whether a repository should be initialized before backing up, try rustic backup --init.

@aawsome aawsome added C-enhancement Category: New feature or request A-cli Area: `rustic` command line interface and removed S-triage Status: Waiting for a maintainer to triage this issue/PR labels Nov 5, 2023
@florensie
Copy link
Author

For my case I need to check the existing snapshots before I do any backups, so unfortunately --init isn't an option. You could consider making --init a global parameter.

@aawsome
Copy link
Member

aawsome commented Nov 14, 2023

Sorry for the late follow-up! Out of curiosity: Can you describe your use case in more detail? What do you want to do and where do you need the information if the repository is initialized?

@aawsome
Copy link
Member

aawsome commented Dec 4, 2023

I just recalled that non-0 exit codes should be already implemented; at least I thought that

 if let Err(err) = self.inner_run() {
            status_err!("{}", err);
            RUSTIC_APP.shutdown(Shutdown::Crash);
        };

should do exactly this. But it seems it doesn't....
@simonsan Can you have a look at it?

@simonsan
Copy link
Contributor

simonsan commented Dec 4, 2023

    /// Shut down this application gracefully, exiting with success.
    fn shutdown(&self, shutdown: Shutdown) -> ! {
        let components = self.state().components();

        if let Err(e) = components.shutdown(self, shutdown) {
            fatal_error(self, &e)
        }

        process::exit(0);
    }

Shutdown always returns 0 as exit code, I might open an issue upstream with abscissa to allow for non-zero exit codes there.

Ref.: iqlusioninc/abscissa#857

@simonsan simonsan added the C-upstream Category: Issue for a dependency, will be fixed upstream label Dec 4, 2023
@aawsome aawsome changed the title Rustic returns exit code 0 when repository is not initialized Rustic returns exit code 0 when errors occur Feb 26, 2024
@aawsome aawsome added the P-high Priority: High, to be fixed at a higher priority label Feb 26, 2024
@simonsan
Copy link
Contributor

simonsan commented Mar 7, 2024

The corresponding PR with delivering an extra method for this has been merged and a new abscissa release will be made soon™️.

@Schweber
Copy link

Is it possible to pin the latest master of abscissa and use this version as a stopgap until a "real" release is made?

@aawsome
Copy link
Member

aawsome commented Jul 7, 2024

@Schweber This is possible - but when uploading a version to crates.io, git dependencies are not allowed, only dependencies to projects/versions also released to crates.io...

This was referenced Aug 31, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 7, 2024
rustic now returns an error code for failing command.

Note: Some command do not fail yet fail in every cases user would expect
is. Most notably the `check` ckommand producing `error` messages may
still return error code 0.

closes #927
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: `rustic` command line interface C-enhancement Category: New feature or request C-upstream Category: Issue for a dependency, will be fixed upstream P-high Priority: High, to be fixed at a higher priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants