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
Fixes a FormatException when a bad string is included in the 'because' clause #764
Conversation
Thanks for having a look into this. I'm a bit hesitant in trying to fix stuff, that throws a In #717 the summary notes for |
@jnyrup I think you're right. We're not going to protect against all inputs that will fail with Should anything be done to make it clearer why there was a FormatException? In This is the code being passed to
|
For the sake of insight, we changed But I agree that a test shouldn't fail, because the |
I can add a try/catch to the |
Something like that could work |
To reformulate myself. A test will only fail from bad
The notes in #717 was written before #725 was merged in. If we go with a fallback reason, I was thinking about something like |
It still seems to me that changing anything in formatting grammar is harmful. Standard formatting grammar is well documented and understood, let's stick to it. On the other hand, I really like the idea of enriching assertion message instead of throwing FormatException to the caller. Even if the reason part is flawed, part of the assertion message would still be rendered, that's desirable property.
@jnyrup what do you think? If I understood you correctly you suggested still throwing |
@krajek I agree with everything you just suggested. |
Let me take a pass at this. I'll undo the changes I proposed in this PR in favor of what I think we're now talking about. |
I made the change proposed by @krajek, except that I also included the original because parameter in the warning message. |
If |
// Assert | ||
//----------------------------------------------------------------------------------------------------------- | ||
act.Should().Throw<XunitException>() | ||
.WithMessage($"*because message '{because}' could not be formatted with string.Format*"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny issue: you are reproducing the logic from production code in tests. I suggest avoiding $ formatting and just prepare expected message manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I embedded the text directly in the expected message with the most recent commit.
Good job, nice improvement. Regarding empty |
} | ||
catch (FormatException formatException) | ||
{ | ||
return $"**WARNING** because message '{because}' could not be formatted with string.Format\r\n{formatException.StackTrace}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of platform independence, please use {Environment.NewLine}
instead of `\r\n.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed a commit with this change.
Looks good to me. |
Looks good to me too. Now, to really help us keep the history clean, I would like you to update the PR so it only includes the final implementation. You can do that by using an interactive rebase and skipping the first commits or by creating a new branch, cherry picking the right commits and force pushing it into the one that is linked to the current PR. Would that work for you? |
… the phrase cannot be formatted
1263ab9
to
9075bdf
Compare
I did the rebase. Please let me know if the commit history and the file changes look like you expect. |
@bernard-chen congrats with your first contribution to Fluent Assertions |
IMPORTANT
SINCE FLUENT ASSERTIONS IS CURRENTLY UNDER HEAVY REFACTORING FOR VERSION 5.0, WE CURRENTLY ONLY ACCEPT BUGFIX REQUESTS. SORRY FOR THE INCONVENIENCE
master
branch.Fixes #756.