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

Open
florensie opened this issue Nov 5, 2023 · 7 comments
Open

Rustic returns exit code 0 when errors occur #927

florensie opened this issue Nov 5, 2023 · 7 comments
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?

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

No branches or pull requests

4 participants