From addaf17dfbbd6fa32fbac635dd222a19709c194f Mon Sep 17 00:00:00 2001 From: David Date: Wed, 4 Jan 2023 08:45:44 +0100 Subject: [PATCH 1/3] fixed truffle console crash for missing metadata in jsonBlob --- packages/core/lib/console.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/core/lib/console.js b/packages/core/lib/console.js index 0da3c165c50..20b9779a429 100644 --- a/packages/core/lib/console.js +++ b/packages/core/lib/console.js @@ -263,21 +263,26 @@ class Console extends EventEmitter { "utf8" ); const json = JSON.parse(body); - const metadata = JSON.parse(json.metadata); - const sources = Object.keys(metadata.sources); - // filter out Truffle's console.log. We don't want users to interact with in the REPL. - // user contracts named console.log will be imported, and a warning will be issued. - if ( - sources.length > 1 || - (sources.length === 1 && - !sources.some(source => { - return ( - source === "truffle/console.sol" || - source === "truffle/Console.sol" - ); - })) - ) { + // Vyper contracts may not have metadata field included, just push them to json blobs + if (json.metadata === undefined) { jsonBlobs.push(json); + } else { + const metadata = JSON.parse(json.metadata); + const sources = Object.keys(metadata.sources); + // filter out Truffle's console.log. We don't want users to interact with in the REPL. + // user contracts named console.log will be imported, and a warning will be issued. + if ( + sources.length > 1 || + (sources.length === 1 && + !sources.some(source => { + return ( + source === "truffle/console.sol" || + source === "truffle/Console.sol" + ); + })) + ) { + jsonBlobs.push(json); + } } } catch (error) { throw new Error(`Error parsing or reading ${file}: ${error.message}`); From 1ae18d60440ba7e2a2f8625e12a4c1acd9f26e41 Mon Sep 17 00:00:00 2001 From: David Preininger <61542192+dPreininger@users.noreply.github.com> Date: Wed, 4 Jan 2023 12:40:15 +0100 Subject: [PATCH 2/3] Comment change Co-authored-by: cds-amal --- packages/core/lib/console.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/lib/console.js b/packages/core/lib/console.js index 20b9779a429..707484e60dd 100644 --- a/packages/core/lib/console.js +++ b/packages/core/lib/console.js @@ -263,7 +263,8 @@ class Console extends EventEmitter { "utf8" ); const json = JSON.parse(body); - // Vyper contracts may not have metadata field included, just push them to json blobs + // Artifacts may not contain metadata. For example, early Solidity versions as well as + // Vyper contracts do not include metadata. Just push them to json blobs. if (json.metadata === undefined) { jsonBlobs.push(json); } else { From 2fa56c584506e53e8a6a37af243f3242fa587b39 Mon Sep 17 00:00:00 2001 From: David Preininger <61542192+dPreininger@users.noreply.github.com> Date: Wed, 4 Jan 2023 12:40:34 +0100 Subject: [PATCH 3/3] Comment order change Co-authored-by: cds-amal --- packages/core/lib/console.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/lib/console.js b/packages/core/lib/console.js index 707484e60dd..f40d11db7e5 100644 --- a/packages/core/lib/console.js +++ b/packages/core/lib/console.js @@ -268,10 +268,10 @@ class Console extends EventEmitter { if (json.metadata === undefined) { jsonBlobs.push(json); } else { - const metadata = JSON.parse(json.metadata); - const sources = Object.keys(metadata.sources); // filter out Truffle's console.log. We don't want users to interact with in the REPL. // user contracts named console.log will be imported, and a warning will be issued. + const metadata = JSON.parse(json.metadata); + const sources = Object.keys(metadata.sources); if ( sources.length > 1 || (sources.length === 1 &&