-
-
Notifications
You must be signed in to change notification settings - Fork 200
Add a 'Did you mean ...' error message in case of an unrecognized API property #150
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
Conversation
@Lyrkan what about saying |
I was so focused on trying to find a single word that I didn't even think of using both of them :) |
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.
Wow! I LOVE this! It's exactly the helpful, teaching way that I want Encore to work. I added 2 minor comments.
index.js
Outdated
@@ -631,6 +633,21 @@ const publicApiProxy = new Proxy(publicApi, { | |||
process.exit(1); // eslint-disable-line | |||
} | |||
}; | |||
} else if (typeof target[prop] === 'undefined') { |
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.
nit pick: since we return in the first if
, this doesn't need to be a nested else if
, it can just be a fresh, un-nested if
.
similarProperty = apiProperty; | ||
minDistance = distance; | ||
} | ||
} |
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.
If you type something totally crazy that is completely not close to anything, it will suggest something, right? In Symfony's core, we use "3" as the maximum distance (if it's more than 3, we don't recommend anything): https://github.com/symfony/symfony/blob/1bb2bc322bc1c2d0e6e70c2a0fa9fc0be90757fd/src/Symfony/Component/ExpressionLanguage/SyntaxError.php#L34.
It probably makes sense to do the same thing here
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.
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.
to be exact, we don't use 3 most of the time. We use strlen(input) / 3
(we have a few cases using 3)
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.
Ah, thanks! I've just changed that at sha: 2e216a4... and indeed, it is a bit more "forgiving" in appropriate situations.
<3 this feature. Thank you @Lyrkan! |
…ecognized API property (Lyrkan) This PR was squashed before being merged into the master branch (closes #150). Discussion ---------- Add a 'Did you mean ...' error message in case of an unrecognized API property This PR aims to improve the error message displayed when an user makes a typo in the name of one of the API methods he's trying to use. Since pictures speak louder than words: **Before**  **After**  Note that the error is triggered when trying to access the property, not when the method is called (since it doesn't exist), hence the "is not a recognized property" message. I'm aware that the use of the "property" word in it may not be ideal, but using "method" instead feels wrong too since we could theoretically have other things than methods in the API object. Commits ------- a16e1af Only add the "Did you mean" message if the levenshtein distance is less than 3 1ceabc1 Add "or method" to the "Did you mean ..." error message d592481 Add a 'Did you mean ...' error message for unrecognized API methods
This PR aims to improve the error message displayed when an user makes a typo in the name of one of the API methods he's trying to use.
Since pictures speak louder than words:
Before

After

Note that the error is triggered when trying to access the property, not when the method is called (since it doesn't exist), hence the "is not a recognized property" message. I'm aware that the use of the "property" word in it may not be ideal, but using "method" instead feels wrong too since we could theoretically have other things than methods in the API object.