Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should maintain a global namespace for instanceof", function(){
var external_errors = require('common-errors');
var TestError = errors.helpers.generateClass('Error');
var err = new errors.Error("This is an error");
var external_err = new external_errors.Error("This is an error");
var test_err = new TestError("This is an error");
assert.notEqual(err.stack, test_err.stack, 'err and new err stacks are not equal');
assert.notEqual(err.stack, external_err.stack, 'err and external err stacks are not equal');
assert.notEqual(test_err.stack, external_err.stack, 'new err and external err stacks are not equal');
assert.equal(err.stack.replace(/:\d+:\d+/, ''), test_err.stack.replace(/:\d+:\d+/, ''), 'err and new err have almost the same stack');
assert.equal(err.stack.replace(/:\d+:\d+/, ''), external_err.stack.replace(/:\d+:\d+/, ''), 'err and external err have almost the same stack');
assert.equal(test_err.stack.replace(/:\d+:\d+/, ''), external_err.stack.replace(/:\d+:\d+/, ''), 'new err and external error have almost the same stack');
assert.ok(err instanceof errors.Error, 'err instanceof its own class');
assert.ok(err instanceof TestError, 'err instanceof a new Error');
assert.ok(err instanceof external_errors.Error, 'err instanceof an external Error');
assert.ok(test_err instanceof errors.Error, 'new err instanceof Error');
assert.ok(test_err instanceof TestError, 'new err instanceof itself');
assert.ok(test_err instanceof external_errors.Error, 'new err instanceof an external Error');
assert.ok(external_err instanceof errors.Error, 'external error instanceof Error');
tmp.dir(value, function (err, dirPath, cleanupCallback) {
if (err) {
reject(new errors.Error('tmp.dir', err));
return;
}
resolve({
dirPath: dirPath,
cleanupCallback: cleanupCallback
});
});
});
result: response
}
} catch (err) {
const errMsg = err.message.replace(/"/g, "'")
l.error('JsonRpcService - method() / ', errMsg)
let error
if (errMsg.match(/^Returned error/)) {
error = new errors.Error(err.message)
} else if (errMsg.match(/^Invalid number of parameters/)) {
error = new errors.ArgumentError('Invalid number of params used', err)
} else if (errMsg.match(/^(?:CONNECTION ERROR|CONNECTION TIMEOUT|Provider not set or invalid)/)) {
error = new errors.ConnectionError('Impossible to connect to node.', err)
} else if (errMsg.match(/^Invalid JSON RPC response/)) {
error = new errors.InvalidOperationError('Invalid JSON RPC response', err)
} else {
error = new errors.Error('Invalid JSON RPC response from node')
}
throw error
}
}
mkdirp(targetPath, function (err) {
if (err) {
reject(new errors.Error('mkdirp', err));
clearMethod();
return;
}
resolve({
path: targetPath,
clearMethod: clearMethod
});
});
});
}
try {
var result = spawn.sync.apply(null, value);
} catch (error) {
process.env.PATH = envPath;
reject(error);
return;
}
process.env.PATH = envPath;
if (result['error']) {
reject(new errors.Error(
'command: ' + prettyFormat(value), result['error']
));
return;
} else if (result['status'] !== 0) {
reject(new errors.Error(
'spawn sync exit status is: ' + prettyFormat(result['status']) +
', command: ' + prettyFormat(value)
));
return;
}
resolve(result);
});
};
throw new errors.NotPermittedError(msg)
}
try {
const response = await web3[opts.network].safe[opts.method].apply(this, opts.params)
return {
id: opts.id || this.randomId(),
jsonrpc: '2.0',
result: response
}
} catch (err) {
const errMsg = err.message.replace(/"/g, "'")
l.error('JsonRpcService - method() / ', errMsg)
let error
if (errMsg.match(/^Returned error/)) {
error = new errors.Error(err.message)
} else if (errMsg.match(/^Invalid number of parameters/)) {
error = new errors.ArgumentError('Invalid number of params used', err)
} else if (errMsg.match(/^(?:CONNECTION ERROR|CONNECTION TIMEOUT|Provider not set or invalid)/)) {
error = new errors.ConnectionError('Impossible to connect to node.', err)
} else if (errMsg.match(/^Invalid JSON RPC response/)) {
error = new errors.InvalidOperationError('Invalid JSON RPC response', err)
} else {
error = new errors.Error('Invalid JSON RPC response from node')
}
throw error
}
}
tmp.dir({ keep: true, unsafeCleanup: true }, function (err, dirPath, cleanupCallback) {
if (err) {
reject(new errors.Error('tmp.dir', err));
return;
}
var clearMethod = cleanupCallback;
var targetPath = path.join(dirPath, targetDir);
mkdirp(targetPath, function (err) {
if (err) {
reject(new errors.Error('mkdirp', err));
clearMethod();
return;
}
resolve({
path: targetPath,
clearMethod: clearMethod
});
});
fs.readFile(filePath, 'utf8', function (err, data) {
if (err) {
reject(new errors.io.FileLoadError(filePath));
return;
}
try {
var contents = JSON.parse(data);
} catch (error) {
reject(new errors.Error('JSON.parse', error));
return;
}
resolve(contents);
});
});
envPath = process.env.PATH;
var command = value[0];
if (path.dirname(command) !== '.') {
process.env.PATH = path.normalize(path.dirname(command)) + path.delimiter + process.env.PATH;
value[0] = path.basename(command);
}
try {
var result = spawn.sync.apply(null, value);
} catch (error) {
process.env.PATH = envPath;
reject(error);
return;
}
process.env.PATH = envPath;
if (result['error']) {
reject(new errors.Error(
'command: ' + prettyFormat(value), result['error']
));
return;
} else if (result['status'] !== 0) {
reject(new errors.Error(
'spawn sync exit status is: ' + prettyFormat(result['status']) +
', command: ' + prettyFormat(value)
));
return;
}
resolve(result);
});
};