Skip to content
This repository has been archived by the owner on Sep 28, 2018. It is now read-only.

Clean up paths when reporting bugs to bugsnag #28

Merged
merged 1 commit into from Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/reporter.js
Expand Up @@ -3,6 +3,7 @@
import _ from 'underscore-plus'
import os from 'os'
import stackTrace from 'stack-trace'
import fs from 'fs-plus'

let API_KEY = '7ddca14cb60cbd1cd12d1b252473b076'
let LIB_VERSION = require('../package.json')['version']
Expand Down Expand Up @@ -44,11 +45,11 @@ let buildExceptionJSON = (error, projectRoot) =>
})


let buildStackTraceJSON = function(error, projectRoot) {
let buildStackTraceJSON = (error, projectRoot) => {
let projectRootRegex = new RegExp(`^${_.escapeRegExp(projectRoot)}[\\/\\\\]`, 'i')
return parseStackTrace(error).map(callSite => {
return {
file: callSite.getFileName().replace(projectRootRegex, '').replace(/\\/g, "/"),
file: normalizePath(callSite.getFileName()),
method: callSite.getMethodName() || callSite.getFunctionName() || "none",
lineNumber: callSite.getLineNumber(),
columnNumber: callSite.getColumnNumber(),
Expand All @@ -57,6 +58,14 @@ let buildStackTraceJSON = function(error, projectRoot) {
})
}

let normalizePath = path => {
return path.replace('file:///', '') // Randomly inserted file url protocols
.replace(/[/]/g, '\\') // Temp switch for Windows home matching
.replace(fs.getHomeDirectory(), '~') // Remove users home dir for apm-dev'ed packages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this before it got merged, but it looks like instead of having to require fs, we can use the already-required os with os.homedir()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of places where fsplus.getHomeDirectory() is used - we should clean them all up together. I'm assuming we can safely drop the node 0.9 stuff now (os.homedir() was introduced in 2.3)

.replace(/\\/g, '/') // Switch \ back to / for everyone
.replace(/.*(\/(app\.asar|packages\/).*)/, '$1') // Remove everything before app.asar or pacakges
}

let getDefaultNotificationParams = () =>
({
userId: atom.config.get('exception-reporting.userId'),
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -9,6 +9,7 @@
"atom": ">0.48.0"
},
"dependencies": {
"fs-plus": "2.9.3",
"node-uuid": "~1.4.7",
"stack-trace": "0.0.9",
"underscore-plus": "1.x"
Expand Down