Atom launch on developer tools


#1

Hi I found this problem using Atom 1.17.2 on Linux Mint 18.
When I launch atom from terminal or gui it doesn’t open. I opens a developer tools window instead.

I still can launch atom with the terminal if I use sudo. This might be a coincidence but the last time I used atom before this bug I launched with sudo for non-related reasons. I’am not sure but I think this bug happened after an update.

Bellow is the info I have. Probably will try a reinstall after this bug report, but I’m copying the .atom folder in case some file is needed for solution. Will update this post if reinstall works.

Atom : 1.17.2
Electron: 1.3.15
Chrome : 52.0.2743.82
Node : 6.5.0

Haven’t messed with any themes configs.

Clicking on the console tab I got this error message:

index.js:87 Error: EACCES: permission denied, open '/home/fabriciojardim/.atom/compile-cache/less/df1b7fbc57dbeed23a8f1f8de95b4dfebcc06066/imports.json'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.module.(anonymous function) [as openSync] (ELECTRON_ASAR.js:168:20)
    at Object.fs.writeFileSync (fs.js:1343:33)
    at Proxy.writeFileSync (/opt/atom/resources/app/node_modules/fs-plus/lib/fs-plus.js:295:1)
    at LessCache.module.exports.LessCache.writeJson (/opt/atom/resources/app/node_modules/less-cache/lib/less-cache.js:212:1)
    at LessCache.module.exports.LessCache.setImportPaths (/opt/atom/resources/app/node_modules/less-cache/lib/less-cache.js:161:1)
    at new LessCache (/opt/atom/resources/app/node_modules/less-cache/lib/less-cache.js:68:1)
    at new LessCompileCache (/opt/atom/resources/app/src/less-compile-cache.js:21:1)
    at ThemeManager.module.exports.ThemeManager.loadLessStylesheet (/opt/atom/resources/app/src/theme-manager.js:283:1)
    at ThemeManager.module.exports.ThemeManager.loadStylesheet (/opt/atom/resources/app/src/theme-manager.js:271:1)
    at ThemeManager.module.exports.ThemeManager.requireStylesheet (/opt/atom/resources/app/src/theme-manager.js:191:1)
    at ThemeManager.module.exports.ThemeManager.reloadBaseStylesheets (/opt/atom/resources/app/src/theme-manager.js:252:1)
    at ThemeManager.module.exports.ThemeManager.loadBaseStylesheets (/opt/atom/resources/app/src/theme-manager.js:248:1)
    at AtomEnvironment.module.exports.AtomEnvironment.initialize (/opt/atom/resources/app/src/atom-environment.js:336:1)
    at module.exports (/opt/atom/resources/app/src/initialize-application-window.js:144:1)
    at setupWindow (file:///opt/atom/resources/app/static/index.js:106:12)
    at window.onload (file:///opt/atom/resources/app/static/index.js:67:9)handleSetupError @ index.js:87

It points to my index.js file, here is the content:

(function () {
  // Eagerly require cached-run-in-this-context to prevent a circular require
  // when using `NativeCompileCache` for the first time.
  require('cached-run-in-this-context')

  const electron = require('electron')
  const path = require('path')
  const Module = require('module')
  const getWindowLoadSettings = require('../src/get-window-load-settings')
  const entryPointDirPath = __dirname
  let blobStore = null
  let useSnapshot = false

  window.onload = function () {
    try {
      const startTime = Date.now()

      process.on('unhandledRejection', function (error, promise) {
        console.error('Unhandled promise rejection %o with error: %o', promise, error)
      })

      // Normalize to make sure drive letter case is consistent on Windows
      process.resourcesPath = path.normalize(process.resourcesPath)

      setupAtomHome()
      const devMode = getWindowLoadSettings().devMode || !getWindowLoadSettings().resourcePath.startsWith(process.resourcesPath + path.sep)
      useSnapshot = !devMode && typeof snapshotResult !== 'undefined'

      if (devMode) {
        const metadata = require('../package.json')
        if (!metadata._deprecatedPackages) {
          try {
            metadata._deprecatedPackages = require('../script/deprecated-packages.json')
          } catch (requireError) {
            console.error('Failed to setup deprecated packages list', requireError.stack)
          }
        }
      } else if (useSnapshot) {
        Module.prototype.require = function (module) {
          const absoluteFilePath = Module._resolveFilename(module, this, false)
          let relativeFilePath = path.relative(entryPointDirPath, absoluteFilePath)
          if (process.platform === 'win32') {
            relativeFilePath = relativeFilePath.replace(/\\/g, '/')
          }
          let cachedModule = snapshotResult.customRequire.cache[relativeFilePath] // eslint-disable-line no-undef
          if (!cachedModule) {
            cachedModule = {exports: Module._load(module, this, false)}
            snapshotResult.customRequire.cache[relativeFilePath] = cachedModule // eslint-disable-line no-undef
          }
          return cachedModule.exports
        }

        snapshotResult.setGlobals(global, process, window, document, console, require) // eslint-disable-line no-undef
      }

      const FileSystemBlobStore = useSnapshot ? snapshotResult.customRequire('../src/file-system-blob-store.js') : require('../src/file-system-blob-store') // eslint-disable-line no-undef
      blobStore = FileSystemBlobStore.load(path.join(process.env.ATOM_HOME, 'blob-store'))

      const NativeCompileCache = useSnapshot ? snapshotResult.customRequire('../src/native-compile-cache.js') : require('../src/native-compile-cache') // eslint-disable-line no-undef
      NativeCompileCache.setCacheStore(blobStore)
      NativeCompileCache.setV8Version(process.versions.v8)
      NativeCompileCache.install()

      if (getWindowLoadSettings().profileStartup) {
        profileStartup(Date.now() - startTime)
      } else {
        setupWindow()
        setLoadTime(Date.now() - startTime)
      }
    } catch (error) {
      handleSetupError(error)
    }
  }

  function setLoadTime (loadTime) {
    if (global.atom) {
      global.atom.loadTime = loadTime
    }
  }

  function handleSetupError (error) {
    const currentWindow = electron.remote.getCurrentWindow()
    currentWindow.setSize(800, 600)
    currentWindow.center()
    currentWindow.show()
    currentWindow.openDevTools()
    console.error(error.stack || error)
  }

  function setupWindow () {
    const CompileCache = useSnapshot ? snapshotResult.customRequire('../src/compile-cache.js') : require('../src/compile-cache') // eslint-disable-line no-undef
    CompileCache.setAtomHomeDirectory(process.env.ATOM_HOME)
    CompileCache.install(process.resourcesPath, require)

    const ModuleCache = useSnapshot ? snapshotResult.customRequire('../src/module-cache.js') : require('../src/module-cache') // eslint-disable-line no-undef
    ModuleCache.register(getWindowLoadSettings())

    const startCrashReporter = useSnapshot ? snapshotResult.customRequire('../src/crash-reporter-start.js') : require('../src/crash-reporter-start') // eslint-disable-line no-undef
    startCrashReporter({_version: getWindowLoadSettings().appVersion})

    const CSON = useSnapshot ? snapshotResult.customRequire('../node_modules/season/lib/cson.js') : require('season') // eslint-disable-line no-undef
    CSON.setCacheDir(path.join(CompileCache.getCacheDirectory(), 'cson'))

    const initScriptPath = path.relative(entryPointDirPath, getWindowLoadSettings().windowInitializationScript)
    const initialize = useSnapshot ? snapshotResult.customRequire(initScriptPath) : require(initScriptPath) // eslint-disable-line no-undef
    return initialize({blobStore: blobStore}).then(function () {
      electron.ipcRenderer.send('window-command', 'window:loaded')
    })
  }

  function profileStartup (initialTime) {
    function profile () {
      console.profile('startup')
      const startTime = Date.now()
      setupWindow().then(function () {
        setLoadTime(Date.now() - startTime + initialTime)
        console.profileEnd('startup')
        console.log('Switch to the Profiles tab to view the created startup profile')
      })
    }

    const webContents = electron.remote.getCurrentWindow().webContents
    if (webContents.devToolsWebContents) {
      profile()
    } else {
      webContents.once('devtools-opened', () => { setTimeout(profile, 1000) })
      webContents.openDevTools()
    }
  }

  function setupAtomHome () {
    if (process.env.ATOM_HOME) {
      return
    }

    // Ensure ATOM_HOME is always set before anything else is required
    // This is because of a difference in Linux not inherited between browser and render processes
    // https://github.com/atom/atom/issues/5412
    if (getWindowLoadSettings() && getWindowLoadSettings().atomHome) {
      process.env.ATOM_HOME = getWindowLoadSettings().atomHome
    }
  }
})()

#2

What happens when you delete the ~/.atom/compile-cache folder?


#4

It works! The most important part at least…
I can launch it from gui.
I still can’t launch atom from the command line without sudo.
I get this message:

/usr/bin/atom: line 123: /home/fabriciojardim/.atom/nohup.out: Permission denied

Thanks for your fast reply!
Very useful to me.

PS. I went to terminal and opened some system folders with sudo and edited and saved some files. This indeed seems to be the cause of the bug as after that I got the same problem again.


#5

You probably ran Atom the first time using sudo, which means that the folders are owned by root. You should sudo chown -R fabriciojardim ~/.atom.


#6

That is strange. I’m using Atom from some time and I’m almost sure I launched it from terminal before without using sudo.

Other strange thing is that the gui launcher is working fine now. Don’t know what I did, but I can’t reproduce the problem as I mentioned in the last part of my previous comment. That was before I follow your last suggestion.

Anyway

I checked the ownership of .atom directory and its contents and they’re already owned by the user fabriciojardim.
There is one notable exception, the file nohup.out is owned by root.

I changed that.
Now I can launch Atom from the terminal without using sudo.

Everything else is working fine, and I can open Atom from gui and command line with and without sudo.

Thanks again for your reply!