MCPcopy Create free account
hub / github.com/wevm/viem / constructor

Method constructor

src/errors/contract.ts:177–261  ·  view source on GitHub ↗
({
    abi,
    data,
    functionName,
    message,
    cause: error,
  }: {
    abi: Abi
    data?: Hex | undefined
    functionName: string
    message?: string | undefined
    cause?: BaseError | Error | undefined
  })

Source from the content-addressed store, hash-verified

175 signature?: Hex | undefined
176
177 constructor({
178 abi,
179 data,
180 functionName,
181 message,
182 cause: error,
183 }: {
184 abi: Abi
185 data?: Hex | undefined
186 functionName: string
187 message?: string | undefined
188 cause?: BaseError | Error | undefined
189 }) {
190 let cause: Error | undefined
191 let decodedData: DecodeErrorResultReturnType | undefined
192 let metaMessages: string[] | undefined
193 let reason: string | undefined
194 if (data && data !== '0x') {
195 try {
196 decodedData = decodeErrorResult({ abi, data, cause: error })
197 const { abiItem, errorName, args: errorArgs } = decodedData
198 if (errorName === 'Error') {
199 reason = (errorArgs as [string])[0]
200 } else if (errorName === 'Panic') {
201 const [firstArg] = errorArgs as [number]
202 reason = panicReasons[firstArg as keyof typeof panicReasons]
203 } else {
204 const errorWithParams = abiItem
205 ? formatAbiItem(abiItem, { includeName: true })
206 : undefined
207 const formattedArgs =
208 abiItem && errorArgs
209 ? formatAbiItemWithArgs({
210 abiItem,
211 args: errorArgs,
212 includeFunctionName: false,
213 includeName: false,
214 })
215 : undefined
216
217 metaMessages = [
218 errorWithParams ? `Error: ${errorWithParams}` : '',
219 formattedArgs && formattedArgs !== '()'
220 ? ` ${[...Array(errorName?.length ?? 0).keys()]
221 .map(() => ' ')
222 .join('')}${formattedArgs}`
223 : '',
224 ]
225 }
226 } catch (err) {
227 cause = err as Error
228 }
229 } else if (message) reason = message
230
231 let signature: Hex | undefined
232 if (cause instanceof AbiErrorSignatureNotFoundError) {
233 signature = cause.signature
234 metaMessages = [

Callers

nothing calls this directly

Calls 3

decodeErrorResultFunction · 0.85
formatAbiItemFunction · 0.85
formatAbiItemWithArgsFunction · 0.85

Tested by

no test coverage detected