macoolka-error
Version:
`macoolka-cache` Build a cache for function
42 lines • 1.17 kB
JavaScript
;
/**
* @file
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.runIOWarn = exports.runIO = void 0;
var genericMessage = "Invariant Violation";
var Error_1 = require("./Error");
/**
* Throw a Error with message when io throw exception
* @desczh
* 当io抛出异常时抛出错误
* @since 0.2.0
*/
function runIO(_a) {
var io = _a.io, message = _a.message, title = _a.title;
try {
return io();
}
catch (error) {
throw new Error((0, Error_1.wrapErrorToString)({ title: title, message: message }));
}
}
exports.runIO = runIO;
/**
* Call warn and return a defualt value when io throw exception
* @desczh
* 当io抛出异常时返回缺省值并调用warn
* @since 0.2.0
*/
function runIOWarn(_a) {
var title = _a.title, io = _a.io, _b = _a.message, message = _b === void 0 ? genericMessage : _b, defaultValue = _a.defaultValue, warn = _a.warn;
try {
return io();
}
catch (error) {
warn && warn((0, Error_1.wrapErrorToString)({ title: title, message: message }));
return defaultValue;
}
}
exports.runIOWarn = runIOWarn;
//# sourceMappingURL=io.js.map