ember-hifi icon indicating copy to clipboard operation
ember-hifi copied to clipboard

Can’t catch the 'All given promises failed' error.

Open chrism opened this issue 4 years ago • 4 comments

Hi, I’m using this approach to load my audio stream, which I took from this comment. https://github.com/nypublicradio/ember-hifi/issues/36#issuecomment-295849383

this.hifi.load([{ url: 'audio-url', mimeType: 'audio/mime'}])
.then(({ sound }) => {
  console.log('loaded sound', sound);
})
.catch(error => {
  console.log('FROM CATCH', error);
})
.finally(() => {
  console.log('finally')
});

When one of the audio streams in the array works, this works great.

A problem arises though if none of the sources are working.

The catch does log the error message, but there’s still an additional uncaught promise error—which looks to be coming from promise-race.

This output (with debug: true in the config)

ember-hifi                  |  given urls: http://not-audio.com/url
hifi-cache                  |  cache miss for http://not-audio.com/url
Could not determine mime type for http://not-audio.com/url
Attempting to play urls with an unknown mime type can be bad for performance. See documentation for more info.
Could not determine mime type for http://not-audio.com/url
Attempting to play urls with an unknown mime type can be bad for performance. See documentation for more info.
Attempting to play urls with an unknown mime type can be bad for performance. See documentation for more info.
ember-hifi                  |  Compatible connections for http://not-audio.com/url: NativeAudio, HLS, Howler
ember-hifi                  |  TRYING: [Native Audio] -> http://not-audio.com/url
not-audio.com/url:1 GET http://not-audio.com/url net::ERR_NAME_NOT_RESOLVED
ember-hifi                  |  FAILED: [Native Audio] -> Audio source format is not supported. (http://not-audio.com/url)
ember-hifi                  |  TRYING: [HLS] -> http://not-audio.com/url
xhr-loader.js:82 GET http://not-audio.com/url net::ERR_NAME_NOT_RESOLVED
ember-hifi                  |  FAILED: [HLS] -> manifestLoadError (http://not-audio.com/url)
ember-hifi                  |  TRYING: [Howler] -> http://not-audio.com/url
xhr-loader.js:82 GET http://not-audio.com/url net::ERR_NAME_NOT_RESOLVED
ember-hifi                  |  FAILED: [Howler] -> No codec support for selected audio sources. (http://not-audio.com/url)
ember-hifi                  |  All promises failed:
ember-hifi                  |  Native Audio: Audio source format is not supported.
ember-hifi                  |  HLS: manifestLoadError
ember-hifi                  |  Howler: No codec support for selected audio sources.
load-aro                    |  _findFirstPlayableSound took 1065ms
**FROM CATCH Error: [ember-hifi] URL Promise failed because: All given promises failed.**
    at hifi.js:223
    at invokeCallback (rsvp.js:493)
    at publish (rsvp.js:476)
    at publishRejection (rsvp.js:412)
    at rsvp.js:19
    at invoke (backburner.js:338)
    at Queue.flush (backburner.js:229)
    at DeferredActionQueues.flush (backburner.js:426)
    at Backburner._end (backburner.js:960)
    at Backburner._boundAutorunEnd (backburner.js:629)
**finally**
promise-race.js:43 Uncaught (in promise) Error: All given promises failed.
    at promise-race.js:43
    at invokeCallback (rsvp.js:493)
    at publish (rsvp.js:476)
    at publishRejection (rsvp.js:412)
    at rsvp.js:19
    at invoke (backburner.js:338)
    at Queue.flush (backburner.js:229)
    at DeferredActionQueues.flush (backburner.js:426)
    at Backburner._end (backburner.js:960)
    at Backburner._boundAutorunEnd (backburner.js:629)

I’d really like to find a way to suppress this error but I’m a bit lost as I feel like it should have already been caught by the load() promise catch?

Thanks for any help I’m struggling a bit with the docs on this.

chrism avatar Aug 15 '20 12:08 chrism

Hey @chrism, looks like this is a legit bug with hifi that nobody has caught until now.

I tried stepping through the code to see what was going on last night, but couldn't yet find what's throwing the error.

jkeen avatar Oct 06 '20 13:10 jkeen

@chrism This is still an issue in ember-hifi, but I will report that the fork of hifi I made called ember-stereo has greatly improved error handling and no longer suffers from this issue. Check out the changes at http://ember-stereo.com

jkeen avatar Sep 07 '21 22:09 jkeen

Oh wow @jkeen thanks for the heads up.

In the end I'm using just howler and some custom code, but Ember Stereo looks like it could be a great upgrade.

Going to take a proper look and give it a try.

Thanks again!

chrism avatar Sep 09 '21 18:09 chrism

If anyone comes to this issue, I could solve it like this:

I added a fallback for source:

  get sources() {
    return [
      {
        url: myRealSrc,
        mimeType: myRealMime,
      },
      {
        url: '/assets/empty.mp3',
        mimeType: 'audio/mpeg',
      },
    ];
  }

Then in the load promise, I could throw and catch my own error:

    const { sound } = await this.hifi.load(this.sources);

    if (sound.url === '/assets/empty.mp3') {
      throw 'Given source should succeed';
    }

And on willDestroy() hook, I had to remove it from cached sounds:

willDestroy() {
  super.willDestroy(...arguments);
  if (this.srcErr) {
    this.hifi.soundCache.reset();
  }
 }

I'm migrating to [email protected]

Glarregle avatar Jul 26 '22 13:07 Glarregle