-
Notifications
You must be signed in to change notification settings - Fork 757
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
class library: improve suggestions in method not found error #4929
class library: improve suggestions in method not found error #4929
Conversation
thanks! but, i don't understand how turning off suggestions for nil solves the problem you raised. |
I was just updating the text above, is it understandable now? |
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.
makes sense now that i've had some time to think about it. i think your point is that messages not being understood by nil are far far more often due to a nil being passed where another object is intended, right?
SCClassLibrary/Common/Core/Error.sc
Outdated
} | ||
reportError { | ||
this.errorString.postln; | ||
suggestion.postln; |
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 really think this should be part of errorString
, so it's printed both at the top and bottom of the log
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.
OK, for convenience this makes sense.
SCClassLibrary/Common/Core/Error.sc
Outdated
} | ||
} | ||
errorString { | ||
^"ERROR: Message '" ++ selector ++ "' not understood." ++ suggestion | ||
^"ERROR: Message '%' not understood by '%'".format(selector, receiver) |
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 think this was better as it was. the receiver is already printed out in a more detailed form below this, and this could also lead to massive printouts if the receiver is a large string or collection.
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.
ok!
SCClassLibrary/Common/Core/Error.sc
Outdated
// to avoid unhelpful suggestions. | ||
if(editDistances[minIndex] <= 3 and: { methodNames[minIndex].similarity(lowerCaseSelector) > 0 }) { | ||
suggestedCorrection = methods[minIndex]; | ||
suggestion = "Did you mean '%'? Or should '%' have been called on another receiver?" |
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.
this feels a bit wordy to me. how's this: "Perhaps you misspelled '%', or meant to call '%' on another receiver?"
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.
much better.
Yes, it is the most common case, not only for nil, but also for many other cases like the one demonstrated above. I also find that an error system should rather give no suggestions than misleading ones. |
for the tools i use that implement this same kind of message, i find it immensely useful, and apparently the maintainers did too. i think we have to disagree here. :) |
Don't get me wrong, I find these suggestions very useful. They only should be correct in a large majority of cases (and I don't mean that it should not guess!). |
Better now? I've added a bit of space, this looks less cluttered to me now. |
SCClassLibrary/Common/Core/Error.sc
Outdated
receiver.dump; | ||
"ARGS:\n".post; | ||
args.dumpAll; | ||
this.errorPathString.post; | ||
if(protectedBacktrace.notNil, { this.postProtectedBacktrace }); | ||
this.dumpBackTrace; | ||
// this.adviceLink.postln; | ||
"^^ The preceding error dump is for %\nRECEIVER: %\n\n\n".postf(this.errorString, receiver); | ||
"\n^^ %\nRECEIVER: %\n\n\n".postf(this.errorString, receiver); |
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.
please keep this as it was, the sections of the printout are very clearly labelled and extra vertical whitespace just leads to more scrolling.
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.
These are only 3 lines out of 40. Maybe give it a second look tomorrow, or we ask others what they think? These things are sometimes a matter of taste, in the end I'm fine with either of course. To me, it is an improvement.
Also I'd really like to get rid of the long "The preceding error dump is for" – it makes it harder to read, and the "^^" are clear indications upward.
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 don't want to solve formatting issues by adding extra blank lines in the middle of a printout; it creates a bad precedent, which i explained before here. i would be much more interested in removing unnecessary information, or changing the way the information is presented, but that would happen outside this PR.
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.
OK, I'm not sure I understand your problem, but fine with me! Let's keep this in mind though.
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.
thanks!
Purpose and Motivation
The current error fixing suggestion can be misleading. Typically, the receiver is wrong, not the message. So when you call:
you get a suggestion that you mistyped
flop
, but it happens to be nil which doesn't understand flop:This branch improves this situation.
If the receiver is nil, no suggestion is made - this seems like a reasonable thing not to do.
Otherwise, we post this:
So that:
This still isn't optimal in all cases, but catches most "misunderstandings".
Types of changes
To-do list