Repository navigation
Fix crash on first launch (#78, #90) - #93
Conversation
fxha
commented
Mar 28, 2018
| Q | A |
|---|---|
| Bug fix? | yes |
| Fixed tickets | #78 and #90 |
| License | MIT |
| this.userDataPath = userDataPath | ||
|
|
||
| if (!fs.existsSync(userDataPath)) { | ||
| mkdir(getPath('userData')) |
There was a problem hiding this comment.
I suppose this will cause error too when getPath('appData') is also not existed?
I am newer in nodejs, I think a ensureDir method needed after I do some research.
const { spawnSync } = require('child_process')
const ensureDir = dir => {
spawnSync('mkdir', ['-p', dir])
}
// or
const fse = require('node-fs-extra')
const ensureDir = dir => {
fse.ensureDirSync(dir)
}What's your opinion?
There was a problem hiding this comment.
I suppose this will cause error too when getPath('appData') is also not existed?
Weird... Seems to be a electron fail. Elsewise fs.mkdirSync(...) will create all directories.
What's your opinion?
No this won't work on Windows and fs.mkdirSync(...) uses mkdir on Unix.
There was a problem hiding this comment.
Weird... Seems to be a electron fail.
This means that if you delete your appData directory electron will throw an exception. Which is weird. Maybe we should check this or use a fallback directory, but actually the directory should always exist.
node does not create all directories, so we have to use your suggestion.
const fse = require('node-fs-extra')
const ensureDir = dir => {
fse.ensureDirSync(dir)
}
There was a problem hiding this comment.
I also prefer the second method, 👍 go ahead!
| fs.mkdirSync(dirPath) | ||
| } catch (e) { | ||
| if (e.code !== 'EEXIST') { | ||
| throw e |
There was a problem hiding this comment.
use log method to write error log to log file
There was a problem hiding this comment.
I think following code is the best case, otherwise Mark Text will crash because of no existing directory.
log(e)
throw e
|
@fxha great! |
|
@fxha aha, please update the Thank you. |