Skip to content

AltConstraint error could be more informative #7092

@mih

Description

@mih

Here is the patch

diff --git a/datalad/support/constraints.py b/datalad/support/constraints.py
index 19ad29912..dd54132f5 100644
--- a/datalad/support/constraints.py
+++ b/datalad/support/constraints.py
@@ -434,8 +434,10 @@ class AltConstraints(_MultiConstraint):
                 return c(value)
             except Exception as e:
                 e_list.append(e)
-        raise ValueError("all alternative constraints (%s) violated while testing value %r"
-                         % (self.constraints, value))
+        raise ValueError(
+            f"{value} does not match any alternative: "
+            f"{self.constraints} {e_list}"
+        )
 
 

It turns:

ValueError: all alternative constraints ([constraint:<class 'list'>(constraint:path), constraint:None]) violated while testing value PosixPath('/home/mih/demo/myproject/inputs/penguins/Materials/HPP_scales_share_Final.xlsx')

into

ValueError: /home/mih/demo/myproject/inputs/penguins/Materials/HPP_scales_share_Final.xlsx does not match any alternative: [constraint:<class 'list'>(constraint:path), constraint:None] [TypeError("'PosixPath' object is not iterable"), ValueError('value must be `None`')]

It is not an option to simply raise ... from ...., because there could be more than one exception to report.

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