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

Allow self.exit_codes to be callable with keyword and custom message #2644

Closed
sphuber opened this issue Mar 26, 2019 · 2 comments · Fixed by #3824
Closed

Allow self.exit_codes to be callable with keyword and custom message #2644

sphuber opened this issue Mar 26, 2019 · 2 comments · Fixed by #3824

Comments

@sphuber
Copy link
Contributor

sphuber commented Mar 26, 2019

The use case was presented where one would like to define a generic exit code for a missing file, where one would always want to use the same exit status, but have a customized exit message that includes for example the exact filename. Currently this is not possible, but maybe it would be possible to extend the syntax to be able to do both:

exit_code_default = self.exit_codes.ERROR_MISSING_FILE
exit_code_custom = self.exit_codes(ERROR_MISSING_FILE, 'File `aiida.out` is missing')

we would have to make the exit_codes property callable and override the behavior to construct a new ExitCode instance with the custom message.

Or maybe even better, we make the ExitCode callable which allows to change the message. This would require the ExitCode to be changed from a named tuple into a class, e.g.:

class ExitCode(object):

    def __init__(self, status, message):
        self.status = status
        self.message = message

    def __call__(self, message):
        self.message = message
        return self
@espenfl
Copy link
Contributor

espenfl commented Jun 13, 2019

Also, consider to accept arguments and unpack into format. In this way, we could define an exit code that takes several parameters.

@espenfl
Copy link
Contributor

espenfl commented Jun 13, 2019

And if we follow this route I guess we make a design decision of not ejecting self.report in addition as the messages are anyway collected end ejected in the report.

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

Successfully merging a pull request may close this issue.

2 participants