-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
Closed
Labels
invalidIssues and PRs that are invalid.Issues and PRs that are invalid.
Description
- Version:6.10
- Platform:64-bit Windows 10
- Subsystem:file system (fs)
Hi I have a bit of code in my application which uses readFile method of Node File System and this code sometimes work but sometimes as I debug I noticed that the callback never gets called here is bits of that code
` import { remote } from "electron"
class FileManager {
constructor () {
this._userDataPath = remote.app.getPath('userData')
}
readJsonFile (fileName) {
const path = require('path')
const filePath = path.join(this._userDataPath, fileName)
// filePath looks like "C:\Users\me\AppData\Roaming\Electron\appName\settings.json" on debugger
const fs = require('fs')
return new Promise((resolve, reject) => {
fs.readFile(filePath, (err, data) => {
// control never reches here
if (err) return reject(err)
try {
return resolve(JSON.parse(data))
} catch (error) {
return reject(error)
}
})
})
}`
and when I debug readFile code
const {readFile} = fs
fs.readFile = function (p, options, callback) {
const [isAsar, asarPath, filePath] = splitPath(p) // p is "C:\Users\me\AppData\Roaming\Electron\appName\settings.json"
if (!isAsar) { // evaluated to true
return readFile.apply(this, arguments) // here it retuns undefined
// and arguments parameter look like below on debugger (just in case)
/// 0:"C:\Users\me\AppData\Roaming\Electron\appName\settings.json"
/// 1:function (err, data)
/// callee:function (p, options, callback)
/// length:2
/// Symbol(Symbol.iterator):
/// function values()
/// __proto__: Obj
}
... and rest of readFile code
why it returns undefined?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
invalidIssues and PRs that are invalid.Issues and PRs that are invalid.