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

The addBookmark() example violates this guide's own advice #41

Open
mislav opened this issue Jul 27, 2015 · 1 comment
Open

The addBookmark() example violates this guide's own advice #41

mislav opened this issue Jul 27, 2015 · 1 comment
Assignees

Comments

@mislav
Copy link

mislav commented Jul 27, 2015

The guide advises “Rejections Should Be Used for Exceptional Situations”.

However, the addBookmark() example suggests using promise rejections to signal that a user decided not to save a bookmark:

If the end-user aborts the request to add the bookmark (e.g., they hit escape, or press a "cancel" button), reject promise with a new DOMException whose name is "AbortError".

A user choosing "cancel" from a "Save/cancel" dialog in their browser is not an exceptional situation. A better implementation of this use-case would be that the promise was resolved in both cases and that the resolved value is a boolean indicating whether the user has accepted saving the bookmark or not.

The downside of this approach is that this example then stops being a demonstration of how to use rejected promises. I think an example for that should better follow this document's own guidelines.

@domenic
Copy link
Member

domenic commented Jul 29, 2015

This is a good question. I want to push back a little and see what you think. But in the end you might be right that just overhauling the example to remove ambiguity would be better.

Part of this is in the name. The name is not requestBookmark() or tryBookmark(). It's addBookmark(). A function called "add bookmark" that fails to add a bookmark seems like an exceptional failure condition.

Maybe the guidance here should be more subtle. E.g., you should not name your functions things like "add bookmark," because that doesn't really reflect how the world works (users have to give permission).

@plinss plinss added this to the 2020-06-01-week milestone May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants