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

webtorrent crash app when torrent info field empty #797

Closed
Lunik opened this issue May 12, 2016 · 6 comments
Closed

webtorrent crash app when torrent info field empty #797

Lunik opened this issue May 12, 2016 · 6 comments

Comments

@Lunik
Copy link
Contributor

@Lunik Lunik commented May 12, 2016

  • WebTorrent version:
    0.93.1
  • Node.js version:
    v6

Some time torrent file don't contain info field and it make my application crash.
Is there a way to log error without crashing the app ?
Maybe with a try catch ?

events.js:160
       throw er; // Unhandled 'error' event
       ^  Error: Torrent is missing required field: info
     at ensure (/home/lunik/torrent/node_modules/parse-torrent-file/index.js:146:20)
     at decodeTorrentFile (/home/lunik/torrent/node_modules/parse-torrent-file/index.js:21:3)
     at parseTorrent (/home/lunik/torrent/node_modules/parse-torrent/index.js:32:12)
     at parseOrThrow (/home/lunik/torrent/node_modules/parse-torrent/index.js:89:23)
     at /home/lunik/torrent/node_modules/parse-torrent/index.js:73:7
     at Unzip.<anonymous> (/home/lunik/torrent/node_modules/simple-get/index.js:59:7)
     at emitNone (events.js:91:20)
     at Unzip.emit (events.js:185:7)
     at endReadableNT (_stream_readable.js:926:12)
     at _combinedTickCallback (internal/process/next_tick.js:74:11)
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 12, 2016

It looks like you're using the parse-torrent package directly, not through WebTorrent right? (I don't see node_modules/webtorrent in your stack trace.)

If you get this error, it means that you're trying to parse an invalid torrent. All torrent need an info section.

Can you share a complete code example? I can point out where you need to handle potential errors.

@Lunik

This comment has been minimized.

Copy link
Contributor Author

@Lunik Lunik commented May 13, 2016

It's weird because I never use parse-torrent directly ...

I use the WebTorrent client right here:

function Client () {
  this.client = new WebTorrent()
  this.torrentLink = ''
}

Client.prototype.download = function (torrentLink) {
  var self = this

  setTimeout(function () {
    self.torrentLink = torrentLink
    Log.echo('Start: ' + torrentLink)

    self.client.add(torrentLink, {
      path: config.torrent.downloads
    }, onTorrent)
  }, 1)
}
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 13, 2016

I see.

So, you should always attach an 'error' event handler to the client object.

client.on('error', function (err) {
  console.log('there was an error: ', err)
})

If you want to distinguish which torrent caused the error, you should attach a listener to the torrent object also:

var torrent = client.add(torrentLink, onTorrent)
torrent.on('error', function (err) {
  console.log('there was an error: ', err)
})
@feross feross closed this May 13, 2016
@Lunik

This comment has been minimized.

Copy link
Contributor Author

@Lunik Lunik commented May 16, 2016

I have done what you told me to do.
But It continue to crash:

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error downloading torrent: socket hang up
    at /home/lunik/torrent/node_modules/parse-torrent/index.js:72:26
    at ClientRequest.<anonymous> (/home/lunik/torrent/node_modules/simple-get/index.js:53:21)
    at ClientRequest.f (/home/lunik/torrent/node_modules/once/once.js:17:25)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at Socket.socketOnEnd (_http_client.js:342:9)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:926:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 16, 2016

@Lunik I think you must have done something wrong. Make sure that you're adding an 'error' handler to both the client and the torrent object.

@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.