MCPcopy Index your code
hub / github.com/nodejs/node / innerFail

Function innerFail

lib/internal/assert/utils.js:101–147  ·  view source on GitHub ↗

* @param {InnerFailOptions} obj

(obj)

Source from the content-addressed store, hash-verified

99 * @param {InnerFailOptions} obj
100 */
101function innerFail(obj) {
102 if (obj.message.length === 0) {
103 obj.message = undefined;
104 } else if (typeof obj.message[0] === 'string') {
105 if (obj.message.length > 1) {
106 obj.message = format(...obj.message);
107 } else {
108 obj.message = obj.message[0];
109 }
110 } else if (isError(obj.message[0])) {
111 if (obj.message.length > 1) {
112 throw new ERR_AMBIGUOUS_ARGUMENT(
113 'message',
114 `The error message was passed as error object "${ErrorPrototypeToString(obj.message[0])}" has trailing arguments that would be ignored.`,
115 );
116 }
117 throw obj.message[0];
118 } else if (typeof obj.message[0] === 'function') {
119 if (obj.message.length > 1) {
120 throw new ERR_AMBIGUOUS_ARGUMENT(
121 'message',
122 `The error message with function "${obj.message[0].name || 'anonymous'}" has trailing arguments that would be ignored.`,
123 );
124 }
125 try {
126 obj.message = obj.message[0](obj.actual, obj.expected);
127 if (typeof obj.message !== 'string') {
128 obj.message = undefined;
129 }
130 } catch {
131 // Ignore and use default message instead
132 obj.message = undefined;
133 }
134 } else {
135 throw new ERR_INVALID_ARG_TYPE(
136 'message',
137 ['string', 'function'],
138 obj.message[0],
139 );
140 }
141
142 const error = new AssertionError(obj);
143 if (obj.generatedMessage !== undefined) {
144 error.generatedMessage = obj.generatedMessage;
145 }
146 throw error;
147}
148
149/**
150 * Internal ok handler delegating to innerFail for message handling.

Callers 7

assert.jsFile · 0.85
notDeepStrictEqualFunction · 0.85
compareExceptionKeyFunction · 0.85
expectsErrorFunction · 0.85
expectsNoErrorFunction · 0.85
internalMatchFunction · 0.85
innerOkFunction · 0.85

Calls 2

formatFunction · 0.50
isErrorFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…