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

class library: improve suggestions in method not found error #4929

Merged

Conversation

telephon
Copy link
Member

@telephon telephon commented May 15, 2020

Purpose and Motivation

The current error fixing suggestion can be misleading. Typically, the receiver is wrong, not the message. So when you call:

nil.flop

you get a suggestion that you mistyped flop, but it happens to be nil which doesn't understand flop:

ERROR: Message 'flop' not understood. Did you mean 'stop'?
RECEIVER:
   nil
ARGS:

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:

"Did you mean '%'? Or should '%' have been called on another receiver?"

So that:

Set[1, 2, 3].flop 

// returns 

ERROR: Message 'flop' not understood by 'Set[ 1, 3, 2 ]'
Did you mean 'stop'? Or should 'flop' have been called on another receiver?
RECEIVER:
Instance of Set {    (0x11bbaff68, gc=78, fmt=00, flg=00, set=02)
  instance variables [2]
    array : instance of Array (0x11b705628, size=6, set=3)
    size : Integer 3
}
ARGS:
CALL STACK:
	DoesNotUnderstandError:reportError
		arg this = <instance of DoesNotUnderstandError>
	Nil:handleError
		arg 
[etc.]

This still isn't optimal in all cases, but catches most "misunderstandings".

Types of changes

  • general improvement

To-do list

  • Code is tested
  • All tests are passing
  • This PR is ready for review

@mossheim
Copy link
Contributor

thanks! but, i don't understand how turning off suggestions for nil solves the problem you raised.

@telephon
Copy link
Member Author

I was just updating the text above, is it understandable now?

Copy link
Contributor

@mossheim mossheim left a 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?

}
reportError {
this.errorString.postln;
suggestion.postln;
Copy link
Contributor

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

Copy link
Member Author

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.

}
}
errorString {
^"ERROR: Message '" ++ selector ++ "' not understood." ++ suggestion
^"ERROR: Message '%' not understood by '%'".format(selector, receiver)
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok!

// 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?"
Copy link
Contributor

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?"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much better.

@mossheim mossheim added the comp: class library SC class library label May 16, 2020
@telephon
Copy link
Member Author

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?

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.

@mossheim
Copy link
Contributor

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. :)

@telephon
Copy link
Member Author

telephon commented May 17, 2020

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!).

@telephon
Copy link
Member Author

Better now? I've added a bit of space, this looks less cluttered to me now.

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);
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@telephon telephon merged commit 13fb9a4 into supercollider:develop May 17, 2020
@mossheim mossheim mentioned this pull request Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: class library SC class library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants