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

TypeError: Cannot read property '0' of undefined at Deluge.addTorrent #70

Closed
abdatta opened this issue Feb 22, 2020 · 1 comment
Closed

Comments

@abdatta
Copy link
Contributor

abdatta commented Feb 22, 2020

(node:4347) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of undefined
    at Deluge.addTorrent (/home/yakubo/nyaa-dl/node_modules/@ctrl/deluge/src/index.ts:272:27)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
(node:4347) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not ha)
(node:4347) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I get this error when trying to add a new torrent. I see the fault lies in this line:

    const res = await this.request<AddTorrentResponse>('web.add_torrents', [[{ path, options }]]);

    if (res.body.result[0][0] === false) {
      throw new Error('Failed to add torrent');
    }

It cannot find [0] of res.body.result[0] cuz it is already undefined. So, I checked the output of this response manually and I found res.body.result returns to be a boolean value for this request. The following is a response I found when manually making the request.

{"id": 3841, "result": null, "error": null}

So, I am fixing this in my PR for the issue #69 by replacing the above code with the following:

    const res = await this.request<AddTorrentResponse>('web.add_torrents', [[{ path, options }]]);

    if (res.body.result === false) {
      throw new Error('Failed to add torrent');
    }
abdatta added a commit to abdatta/deluge that referenced this issue Feb 22, 2020
scttcper pushed a commit that referenced this issue Feb 22, 2020
* Fix bug caused in issue #70

* Add function to update trackers of a torrent by force re-announce

* Add test for updateTorrentTrackers function
@scttcper
Copy link
Owner

Thanks for reporting and making a PR!

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

2 participants