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

Handling stream error events #1275

Open
erikhenriqueal opened this issue Feb 3, 2024 · 0 comments
Open

Handling stream error events #1275

erikhenriqueal opened this issue Feb 3, 2024 · 0 comments

Comments

@erikhenriqueal
Copy link

erikhenriqueal commented Feb 3, 2024

I know that the error Error: aborted is thrown when something is wrong with the ytdl's stream, and I think it's caused by youtube's eventual content update (at least it's what I heard), so I tried to handle this error with ytdl's default event handler, but it wasn't enought.

When the error arises, I try to treat it by just retrying the reproduction of the stream, something like:

import ytdl from 'ytdl-core' // version 4.11.5

const stream = ytdl(url, {
  filter: format => format.hasAudio && !format.hasVideo
    // I realized that some songs could not contain higher quality audio.
    // Additionally, higher audio quality frequently throws more errors like this.
    && (format.audioBitrate === 128 || format.audioSampleRate === '48000' || format.audioSampleRate === '41800' || true)
})

stream.on('error', err => {
  console.log('[ SoundboardPlayer Error ] SoundboardPlayer got an Stream Error:\n', String(err))
  // Retry to play the song by creating another stream
})

It's ok to get this error, but the real problem here is that, instead of treating the error as it was supposed to do, the event handler still throws the error after logging it to the console. The output:

[ SoundboardPlayer Error ] SoundboardPlayer got an Stream Error:
Error: aborted
Error: aborted
    at connResetException (node:internal/errors:787:14)
    at TLSSocket.socketCloseListener (node:_http_client:455:19)
    at TLSSocket.emit (node:events:530:35)
    at node:net:337:12
    at TCP.done (node:_tls_wrap:657:7)
[ERROR] 20:21:55 Error: aborted
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

1 participant