Skip to content

Commit

Permalink
Add custom error classes for pre and post dialers error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
BowTiedRadone committed Feb 5, 2025
1 parent c832641 commit 834596d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
14 changes: 14 additions & 0 deletions dialer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@ export class DialerRegistry {
}
}
}

export class PreDialerError extends Error {
constructor(message: string) {
super(message);
this.name = "Pre-dialer error";
}
}

export class PostDialerError extends Error {
constructor(message: string) {
super(message);
this.name = "Post-dialer error";
}
}
16 changes: 7 additions & 9 deletions invariant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
isTraitReferenceFunction,
} from "./traits";
import { EnrichedContractInterfaceFunction } from "./shared.types";
import { DialerRegistry } from "./dialer";
import { DialerRegistry, PostDialerError, PreDialerError } from "./dialer";

/**
* Runs invariant testing on the target contract and logs the progress. Reports
Expand Down Expand Up @@ -278,7 +278,7 @@ export const checkInvariants = async (
});
}
} catch (e: any) {
throw new Error(`Error in pre dialer: ${e.message}`);
throw new PreDialerError(e.message);
}

try {
Expand Down Expand Up @@ -325,7 +325,7 @@ export const checkInvariants = async (
});
}
} catch (e: any) {
throw new Error(`Error in post dialer: ${e.message}`);
throw new PostDialerError(e.message);
}
} else {
radio.emit(
Expand All @@ -341,12 +341,10 @@ export const checkInvariants = async (
);
}
} catch (error: any) {
// If the pre dialer fails, throw an error.
if (error.message.startsWith("Error in pre dialer")) {
throw error;
}
// If the post dialer fails, throw an error.
if (error.message.startsWith("Error in post dialer")) {
if (
error instanceof PreDialerError ||
error instanceof PostDialerError
) {
throw error;
} else {
// If the function call fails with a runtime error, log a dimmed
Expand Down

0 comments on commit 834596d

Please sign in to comment.