* @param {InnerFailOptions} obj
(obj)
| 99 | * @param {InnerFailOptions} obj |
| 100 | */ |
| 101 | function 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. |
no test coverage detected
searching dependent graphs…