From f1f4b90153d0656fa9e406e207c31a7cd8abcbb7 Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Wed, 17 Apr 2024 13:55:02 -0700 Subject: [PATCH] Improve cde-config error logging --- .../engine/paima-runtime/src/cde-config/loading.ts | 12 +++++++----- .../engine/paima-runtime/src/cde-config/utils.ts | 10 +++++----- packages/paima-sdk/paima-utils/src/config/loading.ts | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/engine/paima-runtime/src/cde-config/loading.ts b/packages/engine/paima-runtime/src/cde-config/loading.ts index 18ffc32af..554e69510 100644 --- a/packages/engine/paima-runtime/src/cde-config/loading.ts +++ b/packages/engine/paima-runtime/src/cde-config/loading.ts @@ -70,7 +70,7 @@ export async function loadChainDataExtensions( ); return [instantiatedExtensions, true]; } catch (err) { - doLog(`[cde-config] Invalid config file: ${err}`); + doLog(`[cde-config] Invalid config file:`, err); return [[], false]; } } @@ -177,16 +177,18 @@ function checkOrError( ): Static { // 1) Check if there are any errors since Value.Decode doesn't give error messages { - const skippableErrors: ValueErrorType[] = [ValueErrorType.Intersect, ValueErrorType.Union]; + const lowPriorityErrors = new Set([ValueErrorType.Intersect, ValueErrorType.Union]); const errors = Array.from(Value.Errors(structure, config)); + const allErrorsLowPriority = errors.every(e => lowPriorityErrors.has(e.type)); for (const error of errors) { // there are many useless errors in this library // ex: 1st error: "foo" should be "bar" in struct Foo // 2nd error: struct Foo is invalid inside struct Config // in this case, the 2nd error is useless as we only care about the 1st error // However, we always want to show the error if for some reason it's the only error - if (errors.length !== 1 && skippableErrors.find(val => val === error.type) != null) continue; + if (!allErrorsLowPriority && lowPriorityErrors.has(error.type)) + continue; console.error({ name: name ?? 'Configuration root', path: error.path, @@ -228,7 +230,7 @@ async function instantiateExtension( contract: getErc20Contract(config.contractAddress, web3s[network]), }; case CdeEntryTypeName.ERC721: - if (await isPaimaErc721(config, web3s[config.network || defaultEvmMainNetworkName])) { + if (await isPaimaErc721(config, web3s[network])) { return { ...config, network, @@ -378,7 +380,7 @@ async function instantiateCdeGeneric( eventSignatureHash, }; } catch (err) { - doLog(`[cde-config]: Fail to initialize Web3 contract with ABI ${config.abiPath}`); + doLog(`[cde-config] Failed to initialize Web3 contract ${config.name} with ABI ${config.abiPath}`); throw err; } } diff --git a/packages/engine/paima-runtime/src/cde-config/utils.ts b/packages/engine/paima-runtime/src/cde-config/utils.ts index 8e0b93c31..ee8a80f91 100644 --- a/packages/engine/paima-runtime/src/cde-config/utils.ts +++ b/packages/engine/paima-runtime/src/cde-config/utils.ts @@ -25,13 +25,13 @@ export function getEarliestStartSlot(config: ChainDataExtension[]): number { } // returns pair [rawAbiFileData, artifactObject.abi] -export async function loadAbi(abiPath: string): Promise { - let abiFileData: string = ''; +export async function loadAbi(abiPath: string): Promise { + let abiFileData: string; try { abiFileData = await fs.readFile(abiPath, 'utf8'); } catch (err) { doLog(`[cde-config] ABI file not found: ${abiPath}`); - return [abiFileData, []]; + return []; } try { let abiJson = JSON.parse(abiFileData); @@ -47,7 +47,7 @@ export async function loadAbi(abiPath: string): Promise { } } } catch (err) { - doLog(`[cde-config] ABI file at ${abiPath} has invalid structure`); + doLog(`[cde-config] ABI file at ${abiPath} has invalid structure`, err); } - return [abiFileData, []]; + return []; } diff --git a/packages/paima-sdk/paima-utils/src/config/loading.ts b/packages/paima-sdk/paima-utils/src/config/loading.ts index 8b4d01e3f..34bd8cb0e 100644 --- a/packages/paima-sdk/paima-utils/src/config/loading.ts +++ b/packages/paima-sdk/paima-utils/src/config/loading.ts @@ -177,7 +177,7 @@ export async function loadConfig(): Promise