Skip to content

CLI toplevel exception reporting hides "cause" #7163

Closed
@mih

Description

@mih

While this is not about a particular exception scenario, here is a concrete use case to help illustrate the problem: I have a command that performs input validation. If that fails a uniform ValueError is raised, and it is raised from the underlying exception representing the specific nature of the validation failure (e.g. TypeError, network down, water too cold, ...).

When such a ValueError reaches the CLI top-level handler, all users get to learn about the issue is:

[ERROR  ] Validation of parameter 'spec' failed (ValueError)

And that is despite the fact that exc.__cause__ is ValueError: URL is not a string at this point.

Two approaches would improve this:

  1. CapturedException's .message would include information on a reported cause.
  2. A patch like this:
diff --git a/datalad/cli/main.py b/datalad/cli/main.py
index c5364f4b3..49b09913a 100644
--- a/datalad/cli/main.py
+++ b/datalad/cli/main.py
@@ -212,7 +212,9 @@ def _run_with_exception_handler(cmdlineargs):
             exit_code = 3
         else:
             # some unforeseen problem
-            lgr.error('%s (%s)', ce.message, ce.name)
+            lgr.error('%s (%s)%s',
+                      ce.message, ce.name,
+                      f': {exc.__cause__}' if exc.__cause__ else '')
         sys.exit(exit_code)

In both cases the output to a user would be more like this:

[ERROR  ] Validation of parameter 'spec' failed (ValueError): URL is not a string

Metadata

Metadata

Assignees

Labels

UXuser experience

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions