diff --git a/providers/process/scancode.js b/providers/process/scancode.js index c32e0440..7bc84ba2 100644 --- a/providers/process/scancode.js +++ b/providers/process/scancode.js @@ -54,6 +54,7 @@ class ScanCodeProcessor extends AbstractProcessor { maxBuffer: 5 * 1024 * 1024 }) } catch (error) { + this.logger.error(error, request.meta) // TODO see if the new version of ScanCode has a better way of differentiating errors if (this._isRealError(error) || this._hasRealErrors(file.name)) { request.markDead('Error', error ? error.message : 'ScanCode run failed') @@ -91,19 +92,26 @@ class ScanCodeProcessor extends AbstractProcessor { // Scan the results file for any errors that are not just timeouts or other known errors // TODO do we need to do this anymore _hasRealErrors(resultFile) { - const results = JSON.parse(fs.readFileSync(resultFile)) - return results.files.some( - file => - file.scan_errors && - file.scan_errors.some(error => { - return !( - error.includes('ERROR: Processing interrupted: timeout after') || - error.includes('ValueError:') || - error.includes('package.json') || - error.includes('UnicodeDecodeError') - ) - }) - ) + try{ + const results = JSON.parse(fs.readFileSync(resultFile)) + return results.files.some( + file => + file.scan_errors && + file.scan_errors.some(error => { + return !( + error.includes('ERROR: Processing interrupted: timeout after') || + error.includes('ValueError:') || + error.includes('package.json') || + error.includes('UnicodeDecodeError') + ) + }) + ) + } catch (e) { + // This might happen if the results file is >512mb, but regardless our error handling should not fail. + this.logger.error(`Could not parse ScanCode results file ${resultFile}: ${e.message}`) + // Assume it's broken if we could not parse it + return true + } } _detectVersion() {