UNPKG

node-op

Version:

Interactive 1Password CLI and installer

44 lines (35 loc) 1.06 kB
'use strict'; var ensureError = require('./chunk-ec31973d.js'); function safeCall(fn) { try { return Promise.resolve(fn()); } catch (exc) { return Promise.reject(exc); } } /** * Provides way to give errors that are thrown by external dependencies a * standard and possibly more meaningful message. * * @param future Function that can throw asynchronously or synchronously * @param message Message to assign to error, if thrown */ async function rethrowAsync(future, throwError) { try { return await safeCall(future); } catch (err) { const error = ensureError.ensureError(err); const newError = throwError({ rethrow: () => new ensureError.AggregateError(error.message, error), withMessage: msg => new ensureError.AggregateError(msg, error), thrown: error, // tslint:disable-next-line:strict-string-expressions toString: () => `${String(error)}` }); if (newError) { throw newError; } // istanbul-ignore-next throw error; } } exports.rethrowAsync = rethrowAsync;