question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

postMessage API inconsistency

See original GitHub issue

Description

Per looking at this example in the documentation of the Web API, I expected my callback to have been called with an Error as the first argument if there’s an issue.

Expected result:

The err callback arg to have been populated with an Error.

Actual result:

The response callback arg is called with an “error data structure”.

Although I had an error handler in place, after a little bit of trial an error, I determined that the success handler was instead being called with the following: { ok: false, error: 'channel_not_found' }.

For what it’s worth, I triggered the above error scenario (trying to publish to a channel that doesn’t exist) to double-check that my logging was working as expected.

Specifically, I’m wrapping webClient.chat.postMessage in a promise and, upon success, I’m acknowledging a message on a queue as processed. However, like mentioned above, I was erroneously acknowledging because I’d expected the error argument to have been provided.

I guess my question is this – I feel like, from an API perspective, I should be handling one scenario or the other. In other words, if the error is always going to be contained within the response argument as an error data structure, then the callback only needs to have one param provided. Conversely, the library could invoke the callback with an Error if the response isn’t successful. But, as of right now, I’m having to handle both possibilities:

    // ... other code
    return new Promise((resolve, reject) => {
      webClient.chat.postMessage(channel, text, {
        as_user: true,
        attachments,
      }, (err, response) => {
        // NOTE: The following two lines specifically.
        const { error } = response;
        if (err || error) return reject(err || error);
        return resolve(response);
      });
    });

I guess I just more or less wanted confirm that this is as-intended from a design perspective, because it definitely caught me off-guard and sent me on a little 5-minute debugging detour! 😄

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
aoberoicommented, Nov 26, 2016

Hey @dsimmons, thanks for providing a detailed recount of your experience. This sort of thing really helps us understand where the rough edges are.

I agree that you shouldn’t have to check both the truthiness of the error parameter and the truthiness of the ok property before deciding there was an error. I’ll mark this as a bug so we can fix that.

One thing I noticed is that you said you were wrapping the API call in a Promise, but you should know that when you don’t pass in a callback, we already return a Promise. That might save you some time.

0reactions
DEGoodmanWilsoncommented, Dec 8, 2016

🙇 It is our pleasure!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jquery postmessage inconsistency - Stack Overflow
I'm trying to use Ben Almans jquery postmessage to resize an iFrame. I'm more or less using his example with different servers and...
Read more >
Iframe postmessage fraud - Information Security Stack Exchange
Is there any way an attacker can "spoof" a message and make it look like it originated from a legitimate iframe? I am...
Read more >
Chrome incompatibilities - Mozilla - MDN Web Docs
Some extension APIs allow an extension to send data from one part of the extension to another, such as runtime.sendMessage() , tabs.sendMessage ......
Read more >
Experience Manager SPA API - Bloomreach
All the communication between an SPA and the Experience manager relies on the postMessage API. The API provides an event-based communication between the...
Read more >
Slack Connect: working with channels between organizations
... and will not work with "foreign" users via the API. For example, you cannot use chat.postMessage with a username set to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found