question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve not supported error messages when using `Equals()`

See original GitHub issue

Description

Running code like the below throws an error "Calling Equals on Assertion classes is not supported."

I understand that this by design and is a helpful guard rail to prevent someone from thinking they’re using an assertion but actually doing an equality operation and the result being thrown away. Nice job there.

I think this error message could be improved. For example, it would be nice in the example below if the exception message also said “Did you mean Be()?”.

Complete minimal example reproducing the issue

var x = 1;
var y = 2;
x.Should().Equals(y);  // throws NotSupportedException

Expected behavior:

Expected the exception to point me in the right direction.

Actual behavior:

I had to search the Internet for the error, found this GitHub site, read the code, realized I was dumb and should have used Be().

Versions

Latest

Additional Information

I will put in a PR if you think that supplementing the Equals() error messages to point the user in the right direction would be useful. For many of the assertions, this might be to suggest Be() but perhaps there are others which would need to use something else? I haven’t looked yet. Many thanks for this very useful library.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
nycdotnetcommented, Sep 18, 2022

I like that. I will work on a PR when I get some time soon. Many thanks for being open to considering improving this error message.

1reaction
jnyrupcommented, Sep 23, 2022

I guess we can make the message specific for the type.

Right, I forgot to add the point, which was that we e.g. want to add overrides of Equals to e.g. ObjectAssertions and GenericCollectionAssertions to properly suggest Be and Equals.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overriding the java equals() method - not working?
In Java, the equals() method that is inherited from Object is: ... override Object 's equals was fine, but not compatible with ArrayList...
Read more >
Error messages explained - EqualsVerifier
EqualsVerifier can be used in Java unit tests to verify whether the contract for the equals and hashCode methods is met. Follow.
Read more >
Power Apps Troubleshooting Error Messages - YouTube
Do you want to get better at Troubleshooting in Power Apps? Then this is your video. We explore a whole bunch of common...
Read more >
Comparing Java objects with equals() and hashcode()
In this Java Challenger you'll learn how equals() and hashcode() combine to make object comparisons efficient and easy in your Java programs ...
Read more >
Error Messages | Help - Zoho Deluge
Solution: The arguments of the subText() function are provided with index numbers such that they do not exceed the length of the text...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found