-
Notifications
You must be signed in to change notification settings - Fork 318
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
expect_snapshot_value()
fails when one attribute contains a function
#1771
Comments
This is very much the nature of |
@hadley I get your point, but still, the error message is very cryptic and it took me a lot of trials-errors to figure out that the problem was I was trying to serialize a function. I am trying to make tests using this very nice package, but unfortunately, that doesn't make me a serialization expert, so I have no idea what is serializable and not. A quick check inside |
I don't see how I could make it less confusing — it tells you that the serialization round-trip failed, and exactly what the difference was, i.e. |
Why are you trying to snapshot the value of a function in this was in the first place? |
I was trying to snapshot the result of a function that, for obscure reasons, has a function as an attribute. I understand the concept of serialization, but the implementation and the limits are beyond my reach. The concept of "round-trip" is still obscure to me, despite my googling. I now at least understand that it is not possible to serialize a function at all. In my example this would mean:
Of course, the check would need to be recursive, that's only for the example. This way, there would be a clear message telling me that the problem was that the attribute This would allow programmers to use |
Ok, first off, I don't think that this is a good candidate for a snapshot test — you should be generally be using these for simple objects that have a clear textual representation, and in general functions aren't a good candidate for this (since they have environments etc). That said, it's definitely possible to serialize a function but in general serializing it to JSON is going to be hard, because JSON isn't rich enough to represent all of R's data types well. I can try and make the error a bit more clear. Currently in your case it is:
And it could maybe be:
|
Hi,
Here is a reprex:
Here, the only style that works is
serialize
, but in my real-life case, it generated a 9.7MB.md
file that is totally unusable.The error message does not inform that the cause of the failure is a function:
I think in this case the function should be ignored and a warning would be enough.
The text was updated successfully, but these errors were encountered: