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

Source for empty promise rejection? #24

Closed
LinusU opened this issue Mar 24, 2018 · 1 comment
Closed

Source for empty promise rejection? #24

LinusU opened this issue Mar 24, 2018 · 1 comment

Comments

@LinusU
Copy link
Collaborator

LinusU commented Mar 24, 2018

I think this got lost under the outdated diff, so reposting here just to be sure:

I was matching the browser API. Even if I reject with an error here, the user can't rely on that, since if the Async Clipboard API is used then it may reject without an error. I thought it was better to be consistent. Will add a comment.

Aha, interesting... I wonder why they would standardize around that 🤔

Do you have a link where I can read about this? I tried searching but to me, it didn't seem like the spec mentioned what the Promise should be rejected with.

In the chrome examples it seems like they reject with a proper error:

navigator.clipboard.writeText('Text to be copied')
  .then(() => {
    console.log('Text copied to clipboard');
  })
  .catch(err => {
    // This can happen if the user denies clipboard permissions:
    console.error('Could not copy text: ', err);
  });

ref: https://developers.google.com/web/updates/2018/03/clipboardapi#copy_writing_text_to_the_clipboard

ping @feross

@feross
Copy link
Owner

feross commented Apr 3, 2018

Yeah, I saw that in the Chrome example too, but it doesn't work in practice. There's no error returned.

The spec explainer omits error arguments:

  navigator.clipboard.writeText("some text").then(function() {
      // Promise resolved successfully.
      console.log("Copied to clipboard successfully!");
  }, function() {
      // Promise rejected.
      console.error("Unable to write to clipboard. :-(");
  });

And the spec itself doesn't say "reject promise P with error", but simply "reject promise P". So I'm led to believe there's no error argument.

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

2 participants