Skip to content

Commit

Permalink
Transaction flow: improved errors (#768)
Browse files Browse the repository at this point in the history
- Log the full error in the console
- Invite users to open the console for more details
- Use error.name as the error box title, if available
  • Loading branch information
bpierre authored Jan 28, 2025
1 parent f5a07bc commit e0b6847
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
18 changes: 11 additions & 7 deletions frontend/app/src/screens/TransactionsScreen/TransactionsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export function TransactionsScreen() {
config: boxTransitionConfig,
});

const errorBoxTransition = useTransition(Boolean(step?.error), {
const errorBoxTransition = useTransition(step?.error, {
keys: (error) => String(Boolean(error)),
from: { height: 0, opacity: 0, transform: "scale(0.97)" },
enter: [
{ height: 48, opacity: 1, transform: "scale(1)" },
Expand Down Expand Up @@ -92,7 +93,7 @@ export function TransactionsScreen() {
status: "error",
}, (s) => ({
status: s.status,
error: s.error ?? "Unknown error",
error: s.error ?? { name: null, message: "Unknown error" },
}))
.with(
{ status: "idle" },
Expand Down Expand Up @@ -228,16 +229,19 @@ export function TransactionsScreen() {
</div>
</div>

{errorBoxTransition((style, show) => (
show && (
{errorBoxTransition((style, error) => (
error && (
<a.div
style={{
...style,
opacity: style.opacity.to([0, 0.5, 1], [0, 0, 1]),
}}
>
<ErrorBox title="Error">
{step.error}
<ErrorBox title={error.name ? `Error: ${error.name}` : "Error"}>
{error.message}
<br />
<br />
Please open your browser console for more information.
</ErrorBox>
</a.div>
)
Expand Down Expand Up @@ -354,7 +358,7 @@ function FlowSteps({
}: {
currentStep: number;
steps: Array<{
error: string | null;
error: { name: string | null; message: string } | null;
id: string;
label: string;
status: FlowStepStatus;
Expand Down
48 changes: 33 additions & 15 deletions frontend/app/src/services/TransactionFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export type FlowStep = {
// artifact is the result of a step,
// e.g. a transaction hash or a signed message
artifact: string | null;
error: string | null;
error: { name: string | null; message: string } | null;
id: string;
status: FlowStepStatus;
};
Expand All @@ -131,7 +131,11 @@ export type FlowStepDeclaration<FlowRequest extends BaseFlowRequest = BaseFlowRe
| { status: "idle" }
| { status: "awaiting-commit"; onRetry: () => void }
| { status: "awaiting-verify" | "confirmed"; artifact: string }
| { status: "error"; error: string; artifact?: string }
| {
status: "error";
error: { name: string | null; message: string };
artifact?: string;
}
>;
};

Expand Down Expand Up @@ -226,18 +230,26 @@ const FlowStateSchema = v.object({
}),
steps: v.union([
v.null(),
v.array(v.object({
id: v.string(),
status: v.union([
v.literal("idle"),
v.literal("awaiting-commit"),
v.literal("awaiting-verify"),
v.literal("confirmed"),
v.literal("error"),
]),
artifact: v.union([v.string(), v.null()]),
error: v.union([v.string(), v.null()]),
})),
v.array(
v.object({
id: v.string(),
status: v.union([
v.literal("idle"),
v.literal("awaiting-commit"),
v.literal("awaiting-verify"),
v.literal("confirmed"),
v.literal("error"),
]),
artifact: v.union([v.string(), v.null()]),
error: v.union([
v.null(),
v.object({
name: v.union([v.string(), v.null()]),
message: v.string(),
}),
]),
}),
),
]),
});

Expand Down Expand Up @@ -457,8 +469,14 @@ function useFlowManager(account: Address | null, isSafe: boolean = false) {
updateFlowStep(stepIndex, {
status: "error",
artifact: currentArtifact,
error: error instanceof Error ? error.message : String(error),
error: error instanceof Error
? {
name: error.name.toLowerCase().trim() === "error" ? null : error.name,
message: error.message,
}
: { name: null, message: String(error) },
});
console.error(`Error at step ${stepIndex}:`, error);
} finally {
runningStepRef.current = null;
}
Expand Down

0 comments on commit e0b6847

Please sign in to comment.