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

Fall back to other formatters when IArgumentValueFormatter.GetArgumentValueAsString throws an exception or returns null #1690

Closed
blairconrad opened this issue Nov 7, 2019 · 8 comments · Fixed by #1734

Comments

@blairconrad
Copy link
Member

From a conversation in #1683. At that point I suggested a throwing a UserCallbackException, but the documentation for that class says it's "An exception thrown when a user-provided callback throws an exception", so if we want to throw, we should either consider a different exception or update the docs for that class.
However, Maybe throwing isn't the best course of action. We're already in an error condition, so derailing that just to tell the user about a different error could confuse things. Perhaps we should just construct a non-null message in its place. Clients who turn nullability warnings on in their test projects will be alerted that null isn't the best return value anyhow.

@blairconrad
Copy link
Member Author

Perhaps we should just replace the null with an indication that the argument value was an object of whatever type it was.

@thomaslevesque
Copy link
Member

Perhaps we should just replace the null with an indication that the argument value was an object of whatever type it was.

Which is the default behavior if there's no custom formatter, no?

@blairconrad
Copy link
Member Author

No. If the value isn't null and there's no custom formatter for the value's type, we will

  • format strings as either "string.Empty" or the string with quotes around it,
  • format enumerables like a comma-separated list of values in "[]"s, where each internal value is formatted according to its type, possibly using custom formatters,
  • format fakes as the FakeDisplayName, and
  • format anything else using ToString

@thomaslevesque
Copy link
Member

So, can't we just do as if there were no custom formatter?

@blairconrad
Copy link
Member Author

We can. I'm in.

@blairconrad
Copy link
Member Author

Marking as breaking, as it's a change in behaviour, but I do not think there's any downside.

@blairconrad blairconrad changed the title Handle null returned from IArgumentValueFormatter.GetArgumentValueAsString Use builtin formatters when null returned from IArgumentValueFormatter.GetArgumentValueAsString Nov 7, 2019
@blairconrad blairconrad added this to the vNext milestone Nov 7, 2019
@blairconrad blairconrad self-assigned this Dec 5, 2019
@blairconrad blairconrad mentioned this issue Dec 5, 2019
16 tasks
@blairconrad blairconrad changed the title Use builtin formatters when null returned from IArgumentValueFormatter.GetArgumentValueAsString Use builtin formatters when IArgumentValueFormatter.GetArgumentValueAsString throws an exception or returns null Dec 5, 2019
@blairconrad
Copy link
Member Author

Late-breaking change! Using best-available fallback formatter whenenver the preferred formatter throws an exception or returns null.

@blairconrad blairconrad changed the title Use builtin formatters when IArgumentValueFormatter.GetArgumentValueAsString throws an exception or returns null Fall back to other formatters when IArgumentValueFormatter.GetArgumentValueAsString throws an exception or returns null Dec 5, 2019
@afakebot
Copy link

This change has been released as part of FakeItEasy 6.0.0-beta.1.

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

Successfully merging a pull request may close this issue.

3 participants