From 994aed9af711bc7aa78d58525d33c30c14d91a9e Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 5 Oct 2016 01:15:49 -0700 Subject: [PATCH] Fix "Cannot read property 'files' of null" This PR fixes one of our number 2 top error (142 error reports today alone): Processes: webtorrent window, platforms: darwin linux win32, versions: pre-0.12 0.14.0 0.17.0 0.17.1 TypeError: Cannot read property 'files' of null at getAudioMetadata (.../build/renderer/webtorrent.js:328:21) at EventEmitter. (.../build/renderer/webtorrent.js:84:74) at emitThree (events.js:116:13) at EventEmitter.emit (events.js:194:7) This error is reproducible if you start webtorrent for the first time and click the WIRED CD torrent. This causes the webtorrent process to get a 'wt-get-audio-metadata' before 'wt-start-torrenting'. You can reproduce it 100% of the time if you force the race condition to show itself by slowing down the sending of the 'wt-start-torrenting' event. (This same error was showing for an unrelated reason in the past: #891) --- src/renderer/controllers/playback-controller.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/renderer/controllers/playback-controller.js b/src/renderer/controllers/playback-controller.js index 358f0b10..6cde7364 100644 --- a/src/renderer/controllers/playback-controller.js +++ b/src/renderer/controllers/playback-controller.js @@ -268,8 +268,16 @@ module.exports = class PlaybackController { state.playing.jumpToTime = jumpToTime // if it's audio, parse out the metadata (artist, title, etc) - if (state.playing.type === 'audio' && !fileSummary.audioInfo) { - ipcRenderer.send('wt-get-audio-metadata', torrentSummary.infoHash, index) + if (torrentSummary.status === 'paused') { + ipcRenderer.once('wt-ready-' + torrentSummary.infoHash, getAudioMetadata) + } else { + getAudioMetadata() + } + + function getAudioMetadata () { + if (state.playing.type === 'audio' && !fileSummary.audioInfo) { + ipcRenderer.send('wt-get-audio-metadata', torrentSummary.infoHash, index) + } } // if it's video, check for subtitles files that are done downloading