Skip to content

Commit

Permalink
feature: ARSN-164 rpc error utils missing is
Browse files Browse the repository at this point in the history
* added a few missing constants
* fix a few more err.is usages
  • Loading branch information
miniscruff committed Apr 25, 2022
1 parent ffe53ab commit 473e241
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
3 changes: 3 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export const permittedCapitalizedBuckets = {
};
/* eslint-disable camelcase */
export const externalBackends = { aws_s3: true, azure: true, gcp: true, pfs: true }
export const hasCopyPartBackends = { aws_s3: true, gcp: true }
export const versioningNotImplBackends = { azure: true, gcp: true }
export const mpuMDStoredExternallyBackend = { aws_s3: true, gcp: true }
// hex digest of sha256 hash of empty string:
export const emptyStringHash = crypto.createHash('sha256').update('', 'binary').digest('hex');
// Default expiration value of the S3 pre-signed URL duration
Expand Down
4 changes: 3 additions & 1 deletion lib/network/rpc/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ module.exports.reconstructError = function reconstructError(err) {
return err;
}
const reconstructedErr = new Error(err.message);

reconstructedErr.is = {
[err.message]: true,
};
Object.keys(err).forEach(k => {
reconstructedErr[k] = err[k];
});
Expand Down
4 changes: 2 additions & 2 deletions lib/storage/data/DataWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class DataWrapper {
return;
}
this._retryDelete(clientGetInfo, log, 0, err => {
if (err && !err.ObjNotFound) {
if (err && !err.is.ObjNotFound) {
log.error('delete error from datastore',
{ error: err, key: objectGetInfo.key, moreRetries: 'no' });
}
Expand Down Expand Up @@ -984,7 +984,7 @@ class DataWrapper {
return this.client.delete(objectGetInfo, log.getSerializedUids(),
err => {
if (err) {
if (err.ObjNotFound) {
if (err.is.ObjNotFound) {
log.info('no such key in datastore', {
objectGetInfo,
implName: this.implName,
Expand Down
22 changes: 9 additions & 13 deletions lib/storage/metadata/file/BucketFileInterface.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const cluster = require('cluster');
const async = require('async');

const errors = require('../../../errors').default;
Expand All @@ -20,7 +19,6 @@ class BucketFileInterface {
/**
* @constructor
* @param {object} [params] - constructor params
* @param {boolean} [params.noDbOpen=false] - true to skip DB open
* @param {object} logger - logger
* (for unit tests only)
*/
Expand All @@ -29,9 +27,6 @@ class BucketFileInterface {
const { host, port } = params.metadataClient;
this.constants = params.constants;
this.mdClient = new MetadataFileClient({ host, port });
if (params && params.noDbOpen) {
return;
}
this.lastItemScanTime = null;
this.lastItemScanResult = null;
}
Expand All @@ -44,16 +39,17 @@ class BucketFileInterface {
// the metastore sublevel is used to store bucket attributes
this.mdDB = value;
this.metastore = this.mdDB.openSub(METASTORE);
if (cluster.isMaster) {
this.setupMetadataServer(done);
}
this.setupMetadataServer(done);
});
}

setupMetadataServer(done) {
/* Since the bucket creation API is expecting the
usersBucket to have attributes, we pre-create the
usersBucket attributes here */
usersBucket attributes here.
This call is idempotent so we are ok calling it many times
when using multiple workers.
*/
this.mdClient.logger.debug('setting up metadata server');
const usersBucketAttr = new BucketInfo(this.constants.usersBucket,
'admin', 'admin', new Date().toJSON(),
Expand Down Expand Up @@ -95,7 +91,7 @@ class BucketFileInterface {

createBucket(bucketName, bucketMD, log, cb) {
this.getBucketAttributes(bucketName, log, err => {
if (err && err !== errors.NoSuchBucket) {
if (err && !err.is.NoSuchBucket) {
return cb(err);
}
if (err === undefined) {
Expand All @@ -114,7 +110,7 @@ class BucketFileInterface {
.withRequestLogger(log)
.get(bucketName, {}, (err, data) => {
if (err) {
if (err.ObjNotFound) {
if (err.is.ObjNotFound) {
return cb(errors.NoSuchBucket);
}
const logObj = {
Expand All @@ -138,7 +134,7 @@ class BucketFileInterface {
db.withRequestLogger(log)
.get(objName, params, (err, objAttr) => {
if (err) {
if (err.ObjNotFound) {
if (err.is.ObjNotFound) {
return cb(null, {
bucket: bucketAttr.serialize(),
});
Expand Down Expand Up @@ -232,7 +228,7 @@ class BucketFileInterface {
}
db.withRequestLogger(log).get(objName, params, (err, data) => {
if (err) {
if (err.ObjNotFound) {
if (err.is.ObjNotFound) {
return cb(errors.NoSuchKey);
}
const logObj = {
Expand Down

0 comments on commit 473e241

Please sign in to comment.