Skip to content

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

Merged
merged 3 commits into from
Sep 14, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add "or method" to the "Did you mean ..." error message
  • Loading branch information
Lyrkan committed Aug 31, 2017
commit 1ceabc1f9c4411a36771d421ab9b2ad82d922388
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ const publicApiProxy = new Proxy(publicApi, {
}
}
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

2017-09-13_23-01-01

2017-09-13_23-02-08

Copy link
Member

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)

Copy link
Member

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.


const error = new Error(`${chalk.red(`Encore.${prop}`)} is not a recognized property, did you mean ${chalk.green(`Encore.${similarProperty}`)}?`);
const error = new Error(`${chalk.red(`Encore.${prop}`)} is not a recognized property or method, did you mean ${chalk.green(`Encore.${similarProperty}`)}?`);
console.log(new PrettyError().render(error));
process.exit(1); // eslint-disable-line
}
Expand Down