From e38c1a15c60799442fb82c12352ba1d2acccf4bd Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Tue, 10 Dec 2024 15:26:27 -0500 Subject: [PATCH] Add more details to errors --- .../core/src/validate-initializers.test.ts | 10 +++++----- packages/core/src/validate/overrides.ts | 2 +- packages/core/src/validate/report.ts | 8 +++++--- packages/core/src/validate/run.ts | 20 ++++++++++++++----- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/packages/core/src/validate-initializers.test.ts b/packages/core/src/validate-initializers.test.ts index e68bbff2e..a5f565962 100644 --- a/packages/core/src/validate-initializers.test.ts +++ b/packages/core/src/validate-initializers.test.ts @@ -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); @@ -81,7 +81,7 @@ 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); @@ -89,7 +89,7 @@ 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'); @@ -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); @@ -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); diff --git a/packages/core/src/validate/overrides.ts b/packages/core/src/validate/overrides.ts index a72f63d44..3f2cf6c05 100644 --- a/packages/core/src/validate/overrides.ts +++ b/packages/core/src/validate/overrides.ts @@ -83,7 +83,7 @@ export const ValidationErrorUnsafeMessages: Record = { 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', }, diff --git a/packages/core/src/validate/run.ts b/packages/core/src/validate/run.ts index de8ea714c..49a13fd74 100644 --- a/packages/core/src/validate/run.ts +++ b/packages/core/src/validate/run.ts @@ -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'; @@ -751,6 +760,7 @@ function* getInitializerErrors( yield { kind: 'missing-initializer-call', src: decodeSrc(contractInitializer), + parentContracts: uninitializedBaseContracts, }; } }