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

Inconsistent error messages #19

Closed
hadley opened this issue Jul 26, 2017 · 4 comments
Closed

Inconsistent error messages #19

hadley opened this issue Jul 26, 2017 · 4 comments

Comments

@hadley
Copy link
Member

hadley commented Jul 26, 2017

library(zeallot)
{x} %<-% list(1, 2)
#> Error: too many values to unpack
{x : y : z : a } %<-% list(1, 2)
#> Error: expecting 4 values, but found 2
@hadley
Copy link
Member Author

hadley commented Jul 26, 2017

A couple more:

library(zeallot)

{x} %<-% list()
{x : y} %<-% list()
#> Error: cannot de-structure list

I also think it would be useful to include %<-% in the error message

@nteetor
Copy link
Member

nteetor commented Jul 26, 2017

You are absolutely right that the error messages need to incorporate "%<-%" somewhere in them.

In general, the error messages were modeled after Python's error messages.

Your first example translated over to Python produces the message below.

#>>> [x] = [1, 2]
#Traceback (most recent call last):
#  File "<stdin>", line 1, in <module>
#ValueError: too many values to unpack

I built the %<-% operator to assume the LHS is correct, thus there are "too many values", not "too few variables", when the RHS has too many values to unpack. This could be elucidated with a better error message.

Similarly, because the LHS is assumed to be correct, when the RHS contains too few values, an error is raised pointing the blame at the RHS.

{x : y : z : a } %<-% list(1, 2)
#> Error: expecting 4 values, but found 2

The LHS expected 4 values, but the RHS only provided 2. An error message along that line might be better suited.

@hadley
Copy link
Member Author

hadley commented Jul 26, 2017

I think all these errors are related to a mismatch between the number of elements on the LHS and RHS, and so should use the same text. I don't think there's a need to mimic python's inconsistencies.

@nteetor
Copy link
Member

nteetor commented Jul 26, 2017

That's fair, always striving to be better. The hope was the different messages help the user identify different problems, but if the messages are counter intuitive then they're self-defeating.

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

No branches or pull requests

2 participants