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

error handling for duplicate torrents #351

Closed
wants to merge 1 commit into from

Conversation

@madd512
Copy link

madd512 commented Jun 7, 2015

I'm mostly happy with this solution.

I'd be even happier if I could detect the error message by a safer means than message string comparison, but I didn't want to over-complicate.

Tests pass.

self.emit('error', err, torrent)
self.remove(torrent)
var alreadyExistsMessage = 'There is already a swarm with info hash'
if (ontorrent && err.message && err.message.substr(0, alreadyExistsMessage.length) === alreadyExistsMessage) {

This comment has been minimized.

Copy link
@madd512

madd512 Jun 7, 2015

Author

Is it okay for this line to be this long?

self.remove(torrent)
var alreadyExistsMessage = 'There is already a swarm with info hash'
if (ontorrent && err.message && err.message.substr(0, alreadyExistsMessage.length) === alreadyExistsMessage) {
self.torrents.splice(self.torrents.indexOf(torrent), 1)

This comment has been minimized.

Copy link
@madd512

madd512 Jun 7, 2015

Author

can't call self.remove because it does other stuff like destroying the torrent

torrent = self.torrents.filter(function (_torrent) {
return torrent.infoHash === _torrent.infoHash
})[0]
process.nextTick(clientOnTorrent.bind(null, torrent))

This comment has been minimized.

Copy link
@madd512

madd512 Jun 7, 2015

Author

calling this immediately causes this test to fail

@madd512

This comment has been minimized.

Copy link
Author

madd512 commented Jun 7, 2015

Just noticing - running client.seed and then later client.add causes the torrent to stop seeding. This is beyond my ken. @feross any ideas?

@feross

This comment has been minimized.

Copy link
Member

feross commented Jun 11, 2015

I think we can solve this more easily by just checking if client.get(torrentId) is truthy before we go forth with creating a new torrent. I don't like the idea of searching the error string.

I used your test cases (thanks!) and solved this using client.get. Released as 0.49.0. Thanks!

@feross feross closed this Jun 11, 2015
@madd512

This comment has been minimized.

Copy link
Author

madd512 commented Jun 11, 2015

Great. I wanted to use client.get for this but couldn't quite figure out how. I'm glad you could.

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

Successfully merging this pull request may close these issues.

None yet

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