From 3c9ad13f88853f2f804e9c2f76de011871eb3e60 Mon Sep 17 00:00:00 2001 From: Jakob Krigovsky Date: Thu, 27 Jul 2017 19:51:15 +0200 Subject: [PATCH] Only call fs.realpathSync() if the file exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lib/utils/style-settings.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/utils/style-settings.js b/lib/utils/style-settings.js index 6dfbcd7..d4eae86 100644 --- a/lib/utils/style-settings.js +++ b/lib/utils/style-settings.js @@ -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