Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Fix: truffle console crash when metadata is missing in JSON artifact #5819

Merged
merged 3 commits into from
Jan 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions packages/core/lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
dPreininger marked this conversation as resolved.
Show resolved Hide resolved
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.
dPreininger marked this conversation as resolved.
Show resolved Hide resolved
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}`);
Expand Down