diff --git a/lib/common/api/crash-reporter.js b/lib/common/api/crash-reporter.js index def77e72f60e..312868e1834a 100644 --- a/lib/common/api/crash-reporter.js +++ b/lib/common/api/crash-reporter.js @@ -1,6 +1,7 @@ 'use strict' const {spawn} = require('child_process') +const os = require('os') const electron = require('electron') const {app} = process.type === 'browser' ? electron : electron.remote const binding = process.atomBinding('crash_reporter') @@ -13,7 +14,7 @@ class CrashReporter { this.productName = options.productName let {autoSubmit, companyName, extra, ignoreSystemCrashHandler, submitURL} = options - this.tempDirectory = app.getPath('temp') + this.tempDirectory = getTempPath() if (this.productName == null) { this.productName = app.getName() } @@ -72,9 +73,18 @@ class CrashReporter { getUploadedReports () { const productName = this.productName != null ? this.productName : app.getName() - const tempDirectory = this.tempDirectory != null ? this.tempDirectory : app.getPath('temp') + const tempDirectory = this.tempDirectory != null ? this.tempDirectory : getTempPath() return binding._getUploadedReports(productName, tempDirectory) } } +const getTempPath = () => { + try { + return app.getPath('temp') + } catch (error) { + // app.getPath may throw so fallback to OS temp directory + return os.tmpdir() + } +} + module.exports = new CrashReporter()