MCPcopy Create free account
hub / github.com/JS-DevTools/ono / ono

Function ono

src/singleton.ts:22–43  ·  view source on GitHub ↗

* Creates a new error with the specified message, properties, and/or inner error. * If an inner error is provided, then the new error will match its type, if possible.

(...args: unknown[])

Source from the content-addressed store, hash-verified

20 * If an inner error is provided, then the new error will match its type, if possible.
21 */
22function ono<E extends ErrorLike, P extends object>(...args: unknown[]) {
23 let originalError = args[0] as ErrorLike | undefined;
24
25 // Is the first argument an Error-like object?
26 if (typeof originalError === "object" && typeof originalError.name === "string") {
27
28 // Try to find an Ono singleton method that matches this error type
29 for (let typedOno of Object.values(onoMap)) {
30 if (typeof typedOno === "function" && typedOno.name === "ono") {
31 let species = typedOno[Symbol.species];
32
33 if (species && species !== Error && (originalError instanceof species || originalError.name === species.name)) {
34 // Create an error of the same type
35 return typedOno.apply(undefined, args);
36 }
37 }
38 }
39 }
40
41 // By default, create a base Error object
42 return ono.error.apply(undefined, args);
43}

Callers 15

makeOuterErrorFunction · 0.50
testExtendedPropertiesFunction · 0.50
testOnoSignaturesFunction · 0.50
format.spec.jsFile · 0.50
newErrorWithNoArgsFunction · 0.50
newErrorWithMessageFunction · 0.50
newErrorWithParamsFunction · 0.50
newErrorWithInnerErrorFunction · 0.50

Calls

no outgoing calls

Tested by 15

makeOuterErrorFunction · 0.40
testExtendedPropertiesFunction · 0.40
testOnoSignaturesFunction · 0.40
newErrorWithNoArgsFunction · 0.40
newErrorWithMessageFunction · 0.40
newErrorWithParamsFunction · 0.40
newErrorWithInnerErrorFunction · 0.40
newErrorWithPropsFunction · 0.40