Skip to content

Commit

Permalink
Add more details to errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Dec 10, 2024
1 parent c08ecfd commit e38c1a1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
10 changes: 5 additions & 5 deletions packages/core/src/validate-initializers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ testValid(
'Child_Of_InitializerModifier_Bad',
'transparent',
false,
'Contract is missing a call to a parent initializer',
'Contract is missing initializer calls for one or more parent contracts: `Parent_InitializerModifier`',
);
testValid('Child_Of_InitializerModifier_UsesSuper_Ok', 'transparent', true);

Expand All @@ -81,15 +81,15 @@ testValid(
'Child_Of_ReinitializerModifier_Bad',
'transparent',
false,
'Contract is missing a call to a parent initializer',
'Contract is missing initializer calls for one or more parent contracts: `Parent_ReinitializerModifier`',
);

testValid('Child_Of_OnlyInitializingModifier_Ok', 'transparent', true);
testValid(
'Child_Of_OnlyInitializingModifier_Bad',
'transparent',
false,
'Contract is missing a call to a parent initializer',
'Contract is missing initializer calls for one or more parent contracts: `Parent__OnlyInitializingModifier`',
);

testValid('MissingInitializer_Bad', 'transparent', false, 'Contract is missing an initializer');
Expand Down Expand Up @@ -118,7 +118,7 @@ testValid(
'InitializationOrder_MissingCall_Bad',
'transparent',
false,
'Contract is missing a call to a parent initializer',
'Contract is missing initializer calls for one or more parent contracts: `C`',
);
testValid('InitializationOrder_MissingCall_UnsafeAllow_Contract', 'transparent', true);
testValid('InitializationOrder_MissingCall_UnsafeAllow_Function', 'transparent', true);
Expand All @@ -128,7 +128,7 @@ testValid(
'InitializationOrder_Duplicate_Bad',
'transparent',
false,
'Contract has duplicate calls to initializer `__B_init` from parent contract `B`',
'Contract has duplicate calls to parent initializer `__B_init` for contract `B`',
);
testValid('InitializationOrder_Duplicate_UnsafeAllow_Contract', 'transparent', true);
testValid('InitializationOrder_Duplicate_UnsafeAllow_Function', 'transparent', true);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/validate/overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const ValidationErrorUnsafeMessages: Record<ValidationError['kind'], stri
],
'missing-initializer': [
`You are using the \`unsafeAllow.missing-initializer\` flag.`,
`Make sure you have manually checked that the contract has an initializer and that it correctly calls any parent initializers.`,
`Make sure you have manually checked that the contract has an initializer and that it correctly calls all parent initializers.`,
],
'missing-initializer-call': [
`You are using the \`unsafeAllow.missing-initializer-call\` flag.`,
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/validate/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ const errorInfo: ErrorDescriptions<ValidationError> = {
link: 'https://zpl.in/upgrades/error-001',
},
'missing-initializer-call': {
msg: () => `Contract is missing a call to a parent initializer`,
hint: () => `Call the parent initializer in your initializer function`,
msg: e =>
`Contract is missing initializer calls for one or more parent contracts: \`${e.parentContracts.join(', ')}\``,
hint: () => `Call the parent initializers in your initializer function`,
link: 'https://zpl.in/upgrades/error-001',
},
'duplicate-initializer-call': {
msg: e => `Contract has duplicate calls to initializer \`${e.parentInitializer}\` from parent contract \`${e.parentContract}\``,
msg: e =>
`Contract has duplicate calls to parent initializer \`${e.parentInitializer}\` for contract \`${e.parentContract}\``,
hint: () => `Only call each parent initializer once`,
link: 'https://zpl.in/upgrades/error-001',
},
Expand Down
20 changes: 15 additions & 5 deletions packages/core/src/validate/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,31 @@ interface ValidationErrorWithName extends ValidationErrorBase {
| 'internal-function-storage';
}

interface ValidationErrorInitializerMissing extends ValidationErrorBase {
kind: 'missing-initializer' | 'missing-initializer-call';
interface ValidationErrorMissingInitializer extends ValidationErrorBase {
kind: 'missing-initializer';
}

interface ValidationErrorInitializerDuplicate extends ValidationErrorBase {
interface ValidationErrorMissingInitializerCall extends ValidationErrorBase {
kind: 'missing-initializer-call';
parentContracts: string[];
}

interface ValidationErrorDuplicateInitializerCall extends ValidationErrorBase {
kind: 'duplicate-initializer-call';
parentInitializer: string;
parentContract: string;
}

interface ValidationErrorInitializerOrder extends ValidationErrorBase {
interface ValidationErrorIncorrectInitializerOrder extends ValidationErrorBase {
kind: 'incorrect-initializer-order';
expectedLinearization: string[];
}

type ValidationErrorInitializer = ValidationErrorInitializerMissing | ValidationErrorInitializerDuplicate | ValidationErrorInitializerOrder;
type ValidationErrorInitializer =
| ValidationErrorMissingInitializer
| ValidationErrorMissingInitializerCall
| ValidationErrorDuplicateInitializerCall
| ValidationErrorIncorrectInitializerOrder;

interface ValidationErrorConstructor extends ValidationErrorBase {
kind: 'constructor';
Expand Down Expand Up @@ -751,6 +760,7 @@ function* getInitializerErrors(
yield {
kind: 'missing-initializer-call',
src: decodeSrc(contractInitializer),
parentContracts: uninitializedBaseContracts,
};
}
}
Expand Down

0 comments on commit e38c1a1

Please sign in to comment.