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

AltConstraint error could be more informative #7092

Closed
mih opened this issue Oct 17, 2022 · 1 comment · Fixed by #7132
Closed

AltConstraint error could be more informative #7092

mih opened this issue Oct 17, 2022 · 1 comment · Fixed by #7132

Comments

@mih
Copy link
Member

mih commented Oct 17, 2022

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.

bpoldrack added a commit to bpoldrack/datalad that referenced this issue Nov 2, 2022
bpoldrack added a commit to bpoldrack/datalad that referenced this issue Nov 2, 2022
bpoldrack added a commit to bpoldrack/datalad that referenced this issue Nov 3, 2022
@yarikoptic-gitmate
Copy link
Collaborator

Issue fixed in 0.18.0

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

Successfully merging a pull request may close this issue.

2 participants