Skip to content

Commit 5a07213

Browse files
Merge pull request #6525 from jeniawhite/evgb-NSFSErrorCodes
Fixing error codes for NSFS
2 parents b920b65 + 6bf1668 commit 5a07213

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/sdk/namespace_fs.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,7 @@ class NamespaceFS {
378378
const file_path = this._get_file_path(params);
379379
const stat = await nb_native().fs.stat(fs_account_config, file_path);
380380
console.log(file_path, stat);
381-
if (isDirectory(stat)) {
382-
const err = new Error('NoSuchKey');
383-
err.code = 'ENOENT';
384-
throw this._translate_object_error_codes(err);
385-
}
381+
if (isDirectory(stat)) throw Object.assign(new Error('NoSuchKey'), { code: 'ENOENT' });
386382
return this._get_object_info(params.bucket, params.key, stat);
387383
} catch (err) {
388384
throw this._translate_object_error_codes(err);

src/test/unit_tests/test_namespace_fs.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ mocha.describe('namespace_fs', function() {
108108
console.log(inspect(res));
109109
});
110110

111+
mocha.it('read_object_md fails on directory head', async function() {
112+
try {
113+
await ns_src.read_object_md({
114+
bucket: src_bkt,
115+
key: src_key.substr(0, src_key.lastIndexOf('/')),
116+
}, dummy_object_sdk);
117+
throw new Error('Should have failed on head of directory');
118+
} catch (error) {
119+
assert.strict.equal(error.message, 'NoSuchKey');
120+
assert.strict.equal(error.code, 'ENOENT');
121+
assert.strict.equal(error.rpc_code, 'NO_SUCH_OBJECT');
122+
}
123+
});
124+
111125
mocha.describe('read_object_stream', function() {
112126

113127
mocha.it('read full', async function() {

0 commit comments

Comments
 (0)