Skip to content

Handling errors and warnings in Payu #673

@jo-basevi

Description

@jo-basevi

It would be good to develop a consistent approach to logging, handling warnings and errors in Payu. Currently for errors, there's a range of:

  • sys.exit('payu: error: ...')
  • Standard exceptions: e.g. raise RuntimeError(...), raise FileNotFoundError(...)
  • Custom exceptions: raise PayuBranchError

For warnings:

  • print('payu: warning: ...')
  • warnings.warn(...)

A benefit of using exceptions is that it is easy for them to be caught and handled. This is a large part why using sys.exit() is discouraged in library code. On the other hand, exceptions with stack traces (and warnings with code line numbers), aren't the most user friendly and it is often showing information that is not required. Though, especially in development, there are cases where it is useful to have stack traces.

An approach could be to catch exceptions in the main CLI entry point code, and then log the error messages and remove the stack trace, and have a clean exit with sys.exit(1). Similarly, the warnings could be configured in the main CLI entry point code to format and log the warnings. We could add a "debug" option flag to the CLI (and/or config.yaml) to include debug logs with stack traces.

A similar approach could be to do above - so keep any global configuration or wrappers around the CLI entry point code, but have custom PayuError type (with more specific sub-classes like PayuConfigError or PayuFileNotFound), then only these exceptions will have a clean error message with no stack trace, and all other exceptions keep their stack trace as before. This will have the benefit that we know the customs exceptions should have a descriptive error message.

Some references:

Metadata

Metadata

Assignees

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