From e0b2e6d84b3f82f80f7226b5928f4e31eb360c64 Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Fri, 23 Dec 2016 10:13:12 -0700 Subject: [PATCH] Get each version in a more safe way; if one field fails, it won't break the whole thing. Fixes https://github.com/brave/browser-laptop/issues/6406 Auditors: @bbondy Test Plan: 1. Remove existing Brave and deleting existing brave-development folder from %appdata% 2. Build from master 3. Open about:brave, verify info is shown; rev may or may not be blank --- app/sessionStore.js | 58 +++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/app/sessionStore.js b/app/sessionStore.js index 89452960c72..e273db38460 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -342,30 +342,48 @@ module.exports.cleanSessionDataOnShutdown = () => { return p } +const safeGetVersion = (fieldName, getFieldVersion) => { + const versionField = { + name: fieldName, + version: undefined + } + try { + if (typeof getFieldVersion === 'function') { + versionField.version = getFieldVersion() + return versionField + } + console.log('ERROR getting value for field ' + fieldName + ' in sessionStore::setVersionInformation(): ', getFieldVersion, ' is not a function') + } catch (e) { + console.log('ERROR getting value for field ' + fieldName + ' in sessionStore::setVersionInformation(): ', e) + } + return versionField +} + /** * version information (shown on about:brave) */ const setVersionInformation = (data) => { - try { - const os = require('os') - const versionInformation = [ - {name: 'Brave', version: app.getVersion()}, - {name: 'rev', version: Channel.browserLaptopRev()}, - {name: 'Muon', version: process.versions['atom-shell']}, - {name: 'libchromiumcontent', version: process.versions['chrome']}, - {name: 'V8', version: process.versions.v8}, - {name: 'Node.js', version: process.versions.node}, - {name: 'Update Channel', version: Channel.channel()}, - {name: 'os.platform', version: os.platform()}, - {name: 'os.release', version: os.release()}, - {name: 'os.arch', version: os.arch()} - ] - data.about = data.about || {} - data.about.brave = { - versionInformation: versionInformation - } - } catch (e) { - console.log('ERROR calling sessionStore::setVersionInformation(): ', e) + const versionFields = [ + ['Brave', app.getVersion], + ['rev', Channel.browserLaptopRev], + ['Muon', () => { return process.versions['atom-shell'] }], + ['libchromiumcontent', () => { return process.versions['chrome'] }], + ['V8', () => { return process.versions.v8 }], + ['Node.js', () => { return process.versions.node }], + ['Update Channel', Channel.channel], + ['os.platform', require('os').platform], + ['os.release', require('os').release], + ['os.arch', require('os').arch] + ] + const versionInformation = [] + + versionFields.forEach((field) => { + versionInformation.push(safeGetVersion(field[0], field[1])) + }) + + data.about = data.about || {} + data.about.brave = { + versionInformation: versionInformation } return data }