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

Add HasCallStack where error can occur #235

Closed
wants to merge 2 commits into from

Conversation

dspies-leapyear
Copy link

When this fails due to an empty list there's no stack trace pointing to the bad "elements" call.

When this fails due to an empty list there's no stack trace pointing to the bad "elements" call.
Copy link
Contributor

@sol sol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires more work for backwards compatibility. However, I think the error message is clear enough even without accurate source locations, so for me personally closing this as won't fix would be ok too.

EDIT: To be clear, I'm not a maintainer. This is just a third party comment.

@@ -197,7 +198,7 @@ frequency xs0 = choose (1, tot) >>= (`pick` xs0)
pick _ _ = error "QuickCheck.pick used with empty list"

-- | Generates one of the given values. The input list must be non-empty.
elements :: [a] -> Gen a
elements :: HasCallStack => [a] -> Gen a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works with recent versions of GHC.

My call-stack package provides a shim for backwards compatibility. @nick8325 are you fine with adding that dependency? If yes, we could also add source locations to e.g. ===.

If not, we would want to CPP the HasCallStack => of the type signature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@sol sol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nick8325 even with this change this will still require GHC 7.4.*.

@dspies-leapyear
Copy link
Author

@sol The error message is certainly clear, but it's not useful for debugging if elements is called in a lot of places. For debugging purposes, I'd like to know which call to elements is causing the failure without having to put trace calls everywhere or create my own elements wrapper (which is what I'm doing currently).

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 this pull request may close these issues.

2 participants