Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize error descriptions (PR 1) #479

Merged
merged 8 commits into from
Sep 28, 2023
Merged

Conversation

zoeyTM
Copy link
Contributor

@zoeyTM zoeyTM commented Sep 20, 2023

  • add errors-list.ts, mimicking the similar structure in hardhat
  • centralized all currently thrown error messages into the above structure
  • adjusted IgnitionError to require one of the new ErrorDescriptor types as an input, rather than a raw string
  • removed IgnitionValidationError as a class since its stack capturing is no longer functioning as originally intended
  • refactored all previous instances of IgnitionValidationError into IgnitionError

fixes #418

@zoeyTM
Copy link
Contributor Author

zoeyTM commented Sep 20, 2023

One open question for this PR is whether or not we want to add an IgnitionPluginError and/or NomicIgnitionPluginError similar to what hardhat has.

@zoeyTM
Copy link
Contributor Author

zoeyTM commented Sep 20, 2023

One open question for this PR is whether or not we want to add an IgnitionPluginError and/or NomicIgnitionPluginError similar to what hardhat has.

Okay I added these and a new question has popped up: should our hardhat-plugin throw NomicIgnitionPluginError or NomicLabsHardhatPluginError (or HardhatPluginError)? Technically it's both an Ignition plugin and a Hardhat plugin, so I'm not quite sure

@zoeyTM zoeyTM changed the title Centralize error descriptions Centralize error descriptions (PR 1) Sep 20, 2023
@@ -0,0 +1,322 @@
export const ERROR_PREFIX = "IGN";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this file is basically copied structurally from the similar files in Hardhat.

number: number;
// Message can use templates. See applyErrorMessageTemplate
message: string;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Hardhat has extra fields here, but I figured we start with the minimum and can always add more later.

*
* @alpha
*/
export class IgnitionError extends Error {
export class CustomError extends Error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardhat does a lot of clever stuff to modify the displayed output of errors inside this class. We currently aren't doing those things, but I wanted to leave room for us to add it later if we decide to.

*/
export class IgnitionValidationError extends IgnitionError {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the validation specific error in favor of a validation category in errors-list.ts. All errors thrown in Ignition core are now IgnitionErrors

*
* @alpha
*/
export class NomicIgnitionPluginError extends IgnitionPluginError {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this and the above IgnitionPluginError again mimicking the similar classes from Hardhat.

*
* @alpha
*/
export class UnsupportedOperationError extends IgnitionError {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error was only being used in one place, so I removed it as well and added the message for it to errors-list.ts

export class UnsupportedOperationError extends IgnitionError {
constructor(message: string) {
super(message);
export function applyErrorMessageTemplate(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy/pasted from Hardhat

super(message);
this.pluginName = pluginName;
Object.setPrototypeOf(this, IgnitionPluginError.prototype);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave the comment that was here before? also, new.target is dynamic, so it works with extensions to this tupe.

@zoeyTM zoeyTM merged commit ec86c8f into development Sep 28, 2023
6 checks passed
@zoeyTM zoeyTM deleted the centralized-errors branch September 28, 2023 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Centralise error descriptions
3 participants