From f9805ab1a5ae1631251c900aab8b5cfb101dd83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 4 Jul 2018 22:43:16 +0200 Subject: [PATCH] Systematically replace all CWD and userPath by just a '.' --- src/helpers/anonymizer.js | 50 +++++++++++++++++++++++++++++++++++---- src/main/bridge.js | 2 ++ src/sentry/install.js | 22 +---------------- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/helpers/anonymizer.js b/src/helpers/anonymizer.js index e9237fb2..d8496637 100644 --- a/src/helpers/anonymizer.js +++ b/src/helpers/anonymizer.js @@ -1,5 +1,47 @@ // @flow +const configDir = (() => { + const { STORYBOOK_ENV } = process.env + if (!STORYBOOK_ENV) return '__NOTHING_TO_REPLACE__' + const { LEDGER_CONFIG_DIRECTORY } = process.env + if (LEDGER_CONFIG_DIRECTORY) return LEDGER_CONFIG_DIRECTORY + const electron = require('electron') + return (electron.app || electron.remote.app).getPath('userData') || '__NOTHING_TO_REPLACE__' +})() + +const cwd = typeof process === 'object' ? process.cwd() || '.' : '__NOTHING_TO_REPLACE__' + +function filepathReplace(path: string) { + if (!cwd) return path + return path.replace(cwd, '.').replace(configDir, '$USER_DATA') +} + +function filepathRecursiveReplacer(obj: mixed) { + if (obj && typeof obj === 'object') { + if (Array.isArray(obj)) { + for (let i = 0; i < obj.length; i++) { + const item = obj[i] + if (typeof item === 'string') { + obj[i] = filepathReplace(item) + } else { + filepathRecursiveReplacer(item) + } + } + } else { + for (const k in obj) { + if (obj.hasOwnProperty(k)) { + const value = obj[k] + if (typeof value === 'string') { + obj[k] = filepathReplace(value) + } else { + filepathRecursiveReplacer(obj[k]) + } + } + } + } + } +} + export default { url: (url: string): string => url @@ -8,9 +50,7 @@ export default { appURI: (uri: string): string => uri.replace(/account\/[^/]/g, 'account/'), - filepath: (filepath: string): string => { - const i = filepath.indexOf('/node_modules') - if (i !== -1) return `.${filepath.slice(i)}` - return filepath - }, + filepath: filepathReplace, + + filepathRecursiveReplacer, } diff --git a/src/main/bridge.js b/src/main/bridge.js index 4cf7d9b4..b36550be 100644 --- a/src/main/bridge.js +++ b/src/main/bridge.js @@ -22,6 +22,7 @@ logger.setProcessShortName('main') // sqlite files will be located in the app local data folder const LEDGER_LIVE_SQLITE_PATH = path.resolve(app.getPath('userData'), 'sqlite') const LEDGER_LOGS_DIRECTORY = process.env.LEDGER_LOGS_DIRECTORY || resolveLogsDirectory() +const LEDGER_CONFIG_DIRECTORY = app.getPath('userData') let internalProcess @@ -51,6 +52,7 @@ const bootInternalProcess = () => { env: { ...process.env, LEDGER_LOGS_DIRECTORY, + LEDGER_CONFIG_DIRECTORY, LEDGER_LIVE_SQLITE_PATH, INITIAL_SENTRY_ENABLED: sentryEnabled, SENTRY_USER_ID: userId, diff --git a/src/sentry/install.js b/src/sentry/install.js index a3651e86..b217f729 100644 --- a/src/sentry/install.js +++ b/src/sentry/install.js @@ -42,27 +42,7 @@ export default (Raven: any, shouldSendCallback: () => boolean, userId: string) = } } - if (data.exception && typeof data.exception === 'object') { - const { exception } = data - if (Array.isArray(exception.values)) { - const { values } = exception - for (const value of values) { - if (value && typeof value === 'object') { - const { stacktrace } = value - if (stacktrace && typeof stacktrace === 'object') { - if (Array.isArray(stacktrace.frames)) { - const { frames } = stacktrace - for (const frame of frames) { - if (frame && typeof frame === 'object' && typeof frame.filename === 'string') { - frame.filename = anonymizer.filepath(frame.filename) - } - } - } - } - } - } - } - } + anonymizer.filepathRecursiveReplacer(data) console.log('Sentry=>', data) // eslint-disable-line return data