Skip to content

Commit

Permalink
Only call fs.realpathSync() if the file exists
Browse files Browse the repository at this point in the history
Files which are deleted that Atom currently has open will have a path but won’t actually exist in the file system. This caused us to throw a TypeError (see #168). To avoid this, we simply use the path returned by TextEditor::getPath() if the file does not exist.

To avoid confusion, I have also renamed the `relativeActivePanePath` and `activePanePath` variables to a single `activePanePath` variable.

Fixes #168 and closes #174.
  • Loading branch information
sonicdoe committed Jul 27, 2017
1 parent 63a7082 commit 3c9ad13
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/utils/style-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ function checkStyleSettings (filePath) {
return settings
}

var relativeActivePanePath = activePane.getPath()
var activePanePath = activePane.getPath()

if (!relativeActivePanePath) {
if (!activePanePath) {
settings.style = 'no-style'
return settings
}

var absoluteActivePanePath = fs.realpathSync(relativeActivePanePath)
try {
activePanePath = fs.realpathSync(activePanePath)
} catch (e) {
if (e.code !== 'ENOENT') throw e
}

var projectPaths = atom.project.getPaths()

projectPath = projectPaths.find((p) => absoluteActivePanePath.indexOf(fs.realpathSync(p)) >= 0)
projectPath = projectPaths.find((p) => activePanePath.indexOf(fs.realpathSync(p)) >= 0)
} catch (e) {
console.error('Could not get project path', e)
return
Expand Down

0 comments on commit 3c9ad13

Please sign in to comment.