- Add GETTING_STARTED.md with quick start guide and development modes - Add INSTALL.sh automated installation script - Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md - Add QUICK_REFERENCE.md for common commands - Add SETUP_GUIDE.md with detailed setup instructions - Update README.md with improved project overview - Add did-wallet app dependencies and node_modules
68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
import { assertError, isError } from "./error.js";
|
|
import { parseArguments } from "./tools.js";
|
|
export class Layerr extends Error {
|
|
constructor(errorOptionsOrMessage, messageText) {
|
|
const args = [...arguments];
|
|
const { options, shortMessage } = parseArguments(args);
|
|
let message = shortMessage;
|
|
if (options.cause) {
|
|
message = `${message}: ${options.cause.message}`;
|
|
}
|
|
super(message);
|
|
this.message = message;
|
|
if (options.name && typeof options.name === "string") {
|
|
this.name = options.name;
|
|
}
|
|
else {
|
|
this.name = "Layerr";
|
|
}
|
|
if (options.cause) {
|
|
Object.defineProperty(this, "_cause", { value: options.cause });
|
|
}
|
|
Object.defineProperty(this, "_info", { value: {} });
|
|
if (options.info && typeof options.info === "object") {
|
|
Object.assign(this._info, options.info);
|
|
}
|
|
if (Error.captureStackTrace) {
|
|
const ctor = options.constructorOpt || this.constructor;
|
|
Error.captureStackTrace(this, ctor);
|
|
}
|
|
}
|
|
static cause(err) {
|
|
assertError(err);
|
|
if (!err._cause)
|
|
return null;
|
|
return isError(err._cause) ? err._cause : null;
|
|
}
|
|
static fullStack(err) {
|
|
assertError(err);
|
|
const cause = Layerr.cause(err);
|
|
if (cause) {
|
|
return `${err.stack}\ncaused by: ${Layerr.fullStack(cause)}`;
|
|
}
|
|
return err.stack;
|
|
}
|
|
static info(err) {
|
|
assertError(err);
|
|
const output = {};
|
|
const cause = Layerr.cause(err);
|
|
if (cause) {
|
|
Object.assign(output, Layerr.info(cause));
|
|
}
|
|
if (err._info) {
|
|
Object.assign(output, err._info);
|
|
}
|
|
return output;
|
|
}
|
|
cause() {
|
|
return Layerr.cause(this);
|
|
}
|
|
toString() {
|
|
let output = this.name || this.constructor.name || this.constructor.prototype.name;
|
|
if (this.message) {
|
|
output = `${output}: ${this.message}`;
|
|
}
|
|
return output;
|
|
}
|
|
}
|