Browse Source

Systematically replace all CWD and userPath by just a '.'

master
Gaëtan Renaudeau 7 years ago
parent
commit
f9805ab1a5
  1. 50
      src/helpers/anonymizer.js
  2. 2
      src/main/bridge.js
  3. 22
      src/sentry/install.js

50
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/<HIDDEN>'),
filepath: (filepath: string): string => {
const i = filepath.indexOf('/node_modules')
if (i !== -1) return `.${filepath.slice(i)}`
return filepath
},
filepath: filepathReplace,
filepathRecursiveReplacer,
}

2
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,

22
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

Loading…
Cancel
Save