Skip to content

Allow non-zero exit codes with Application::shutdown() #857

@simonsan

Description

@simonsan

Currently, shutdown always returns 0 as exit code:

/// 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);
}

As a user of abscissa I would expect the following to return a non-zero exit code, when I pass Shutdown::Crash, though.

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

What's the opinion on changing that, to allow non-zero exit codes? We could directly return and call process::exit() ourselves, for sure. I'm unsure, though, whether it wouldn't be nice to stay within abscissa to let all the other components shutting down gracefully, while still exiting with a non-zero exit code.

EDIT:

Maybe utilizing https://docs.rs/exitcode/1.1.2/exitcode/ these numbers?

 /// Shut down this application gracefully, exiting with your given `exit_code`. 
 fn shutdown_with_exit_code(&self, shutdown: Shutdown, exit_code: i32) -> ! { 
     let components = self.state().components(); 
  
     if let Err(e) = components.shutdown(self, shutdown) { 
         fatal_error(self, &e) 
     }; 
   
     process::exit(exit_code); 
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions