Skip to content

Commit

Permalink
Improve error message details
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Dec 10, 2024
1 parent b65c2b8 commit c08ecfd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/validate-initializers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ testValid(
'InitializationOrder_Duplicate_Bad',
'transparent',
false,
'Contract has multiple calls to a parent initializer',
'Contract has duplicate calls to initializer `__B_init` from parent contract `B`',
);
testValid('InitializationOrder_Duplicate_UnsafeAllow_Contract', 'transparent', true);
testValid('InitializationOrder_Duplicate_UnsafeAllow_Function', 'transparent', true);
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/validate/overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ 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 correct calls any parent initializers.`,
`Make sure you have manually checked that the contract has an initializer and that it correctly calls any parent initializers.`,
],
'missing-initializer-call': [
`You are using the \`unsafeAllow.missing-initializer-call\` flag.`,
`Make sure you have manually checked that the contract has an initializer and that it correct calls any parent initializers.`,
`Make sure you have manually checked that the contract initializer calls all parent initializers.`,
],
'duplicate-initializer-call': [
`You are using the \`unsafeAllow.duplicate-initializer-call\` flag.`,
`Make sure you have manually checked that the contract has an initializer and that it correct calls any parent initializers.`,
`Make sure you have manually checked that the contract initializer calls each parent initializer only once.`,
],
'incorrect-initializer-order': [
`You are using the \`unsafeAllow.incorrect-initializer-order\` flag.`,
`Make sure you have manually checked that the contract has an initializer and that it correct calls any parent initializers.`,
`Make sure you have manually checked that the contract initializer calls parent initializers in linearized inheritance order.`,
],
};

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/validate/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const errorInfo: ErrorDescriptions<ValidationError> = {
link: 'https://zpl.in/upgrades/error-001',
},
'duplicate-initializer-call': {
msg: () => `Contract has multiple calls to a parent initializer`,
msg: e => `Contract has duplicate calls to initializer \`${e.parentInitializer}\` from parent contract \`${e.parentContract}\``,
hint: () => `Only call each parent initializer once`,
link: 'https://zpl.in/upgrades/error-001',
},
Expand Down
14 changes: 11 additions & 3 deletions packages/core/src/validate/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,22 @@ interface ValidationErrorWithName extends ValidationErrorBase {
| 'internal-function-storage';
}

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

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

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

type ValidationErrorInitializer = ValidationErrorInitializerCall | ValidationErrorInitializerOrder;
type ValidationErrorInitializer = ValidationErrorInitializerMissing | ValidationErrorInitializerDuplicate | ValidationErrorInitializerOrder;

interface ValidationErrorConstructor extends ValidationErrorBase {
kind: 'constructor';
Expand Down Expand Up @@ -709,6 +715,8 @@ function* getInitializerErrors(
yield {
kind: 'duplicate-initializer-call',
src: decodeSrc(fnCall),
parentInitializer: foundParentInitializer.name,
parentContract: baseName,
};
}
calledInitializerIds.push(referencedFn);
Expand Down

0 comments on commit c08ecfd

Please sign in to comment.