size_t size;
njs_int_t ret;
njs_value_t value;
+ const char *code;
njs_object_t *error;
static const njs_value_t string_errno = njs_string("errno");
+ static const njs_value_t string_code = njs_string("code");
static const njs_value_t string_path = njs_string("path");
static const njs_value_t string_syscall = njs_string("syscall");
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
+
+ code = njs_errno_string(errn);
+ size = njs_strlen(code);
+
+ ret = njs_string_new(vm, &value, (u_char *) code, size, size);
+ if (njs_slow_path(ret != NJS_OK)) {
+ return NJS_ERROR;
+ }
+
+ ret = njs_value_property_set(vm, retval, njs_value_arg(&string_code),
+ &value);
+ if (njs_slow_path(ret != NJS_OK)) {
+ return NJS_ERROR;
+ }
}
if (path != NULL) {
fs.accessSync(fname + '___');
failed = true;
} catch(e) {
- failed = (e.syscall != 'access');
- // TODO: e.code != 'ENOENT'
+ failed = (e.syscall != 'access') || e.code != 'ENOENT';
}
resolve(failed);
} catch (e) {
fs.access(fname, fs.constants.R_OK | fs.constants.W_OK, (err) => {
failed |= (err !== undefined);
fs.access(fname + '___', (err) => {
- failed |= ((err === undefined) || (err.syscall != 'access'));
+ failed |= ((err === undefined) || (err.syscall != 'access')
+ || err.code != 'ENOENT');
resolve(failed);
});
});
console.log('testPromise failed');
})
.catch((e) => {
- console.log('testPromise ok', (e.syscall == 'access') && (e.path == fname + '___'));
+ console.log('testPromise ok', (e.syscall == 'access') && (e.path == fname + '___')
+ && e.code == 'ENOENT');
})
;
fs.realpathSync(fname);
throw new Error('fs.realpathSync error 1');
} catch (e) {
- if (e.syscall != 'realpath') { // e.code
+ if (e.syscall != 'realpath' || e.code != 'ENOENT') {
throw e;
}
}
reject(new Error('fs.realpath error 1'));
return;
}
- if (err.syscall != 'realpath') {
+ if (err.syscall != 'realpath' || err.code != 'ENOENT') {
reject(err);
return;
}
.then(() => fsp.realpath(fname)
.then(() => { throw new Error('fsp.realpath error 1') }))
.catch((e) => {
- if (e.syscall != 'realpath') {
+ if (e.syscall != 'realpath' || e.code != 'ENOENT') {
throw e;
}
})
{"var fs = require('fs'); \r\n"
"undefined\r\n>> "}
{"fs.readFile('test/fs/nonexistent', 'utf8', function (e) {console.log(JSON.stringify(e))})\r\n"
- "undefined\r\n{\"errno\":2,\"path\":\"test/fs/nonexistent\",\"syscall\":\"open\"}\r\n>> "}
+ "undefined\r\n{\"errno\":2,\"code\":\"ENOENT\",\"path\":\"test/fs/nonexistent\",\"syscall\":\"open\"}\r\n>> "}
}
njs_test {
{"var fs = require('fs'); \r\n"
"undefined\r\n>> "}
{"try { fs.readFileSync('test/fs/nonexistent')} catch (e) {console.log(JSON.stringify(e))}\r\n"
- "{\"errno\":2,\"path\":\"test/fs/nonexistent\",\"syscall\":\"open\"}\r\nundefined\r\n>> "}
+ "{\"errno\":2,\"code\":\"ENOENT\",\"path\":\"test/fs/nonexistent\",\"syscall\":\"open\"}\r\nundefined\r\n>> "}
}
njs_test {
{"var fs = require('fs')\r\n"
"undefined\r\n>> "}
{"fs.writeFile('/invalid_path', 'ABC', function (e) { console.log(JSON.stringify(e))})\r\n"
- "undefined\r\n{\"errno\":13,\"path\":\"/invalid_path\",\"syscall\":\"open\"}\r\n>> "}
+ "undefined\r\n{\"errno\":13,\"code\":\"EACCES\",\"path\":\"/invalid_path\",\"syscall\":\"open\"}\r\n>> "}
}
# require('fs').writeFileSync()