forked from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from scaffold-eth/backmerge-main-23-05
Co-authored-by: Pablo Alayeto <[email protected]>
- Loading branch information
Showing
6 changed files
with
58 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-eth": patch | ||
--- | ||
|
||
Bump wagmi, viem and rainbowkit versions (scaffold-eth#849) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-eth": patch | ||
--- | ||
|
||
Add default favicon (scaffold-eth#851) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 23 additions & 19 deletions
42
templates/base/packages/nextjs/utils/scaffold-eth/getParsedError.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
import { BaseError as BaseViemError, DecodeErrorResultReturnType } from "viem"; | ||
import { BaseError as BaseViemError, ContractFunctionRevertedError } from "viem"; | ||
|
||
/** | ||
* Parses an viem/wagmi error to get a displayable string | ||
* @param e - error object | ||
* @returns parsed error string | ||
*/ | ||
export const getParsedError = (e: any): string => { | ||
let message: string = e.message ?? "An unknown error occurred"; | ||
if (e instanceof BaseViemError) { | ||
if (e.details) { | ||
message = e.details; | ||
} else if (e.shortMessage) { | ||
message = e.shortMessage; | ||
const cause = e.cause as { data?: DecodeErrorResultReturnType } | undefined; | ||
// if its not generic error, append custom error name and its args to message | ||
if (cause?.data && cause.data?.errorName !== "Error") { | ||
const customErrorArgs = cause.data.args?.toString() ?? ""; | ||
message = `${message.replace(/reverted\.$/, "reverted with following reason:")}\n${ | ||
cause.data.errorName | ||
export const getParsedError = (error: any): string => { | ||
const parsedError = error?.walk ? error.walk() : error; | ||
|
||
if (parsedError instanceof BaseViemError) { | ||
if (parsedError.details) { | ||
return parsedError.details; | ||
} | ||
|
||
if (parsedError.shortMessage) { | ||
if ( | ||
parsedError instanceof ContractFunctionRevertedError && | ||
parsedError.data && | ||
parsedError.data.errorName !== "Error" | ||
) { | ||
const customErrorArgs = parsedError.data.args?.toString() ?? ""; | ||
return `${parsedError.shortMessage.replace(/reverted\.$/, "reverted with the following reason:")}\n${ | ||
parsedError.data.errorName | ||
}(${customErrorArgs})`; | ||
} | ||
} else if (e.message) { | ||
message = e.message; | ||
} else if (e.name) { | ||
message = e.name; | ||
|
||
return parsedError.shortMessage; | ||
} | ||
|
||
return parsedError.message ?? parsedError.name ?? "An unknown error occurred"; | ||
} | ||
|
||
return message; | ||
return parsedError?.message ?? "An unknown error occurred"; | ||
}; |