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

Commit addaf17

Browse files
committed
fixed truffle console crash for missing metadata in jsonBlob
1 parent bf91e46 commit addaf17

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

packages/core/lib/console.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,21 +263,26 @@ class Console extends EventEmitter {
263263
"utf8"
264264
);
265265
const json = JSON.parse(body);
266-
const metadata = JSON.parse(json.metadata);
267-
const sources = Object.keys(metadata.sources);
268-
// filter out Truffle's console.log. We don't want users to interact with in the REPL.
269-
// user contracts named console.log will be imported, and a warning will be issued.
270-
if (
271-
sources.length > 1 ||
272-
(sources.length === 1 &&
273-
!sources.some(source => {
274-
return (
275-
source === "truffle/console.sol" ||
276-
source === "truffle/Console.sol"
277-
);
278-
}))
279-
) {
266+
// Vyper contracts may not have metadata field included, just push them to json blobs
267+
if (json.metadata === undefined) {
280268
jsonBlobs.push(json);
269+
} else {
270+
const metadata = JSON.parse(json.metadata);
271+
const sources = Object.keys(metadata.sources);
272+
// filter out Truffle's console.log. We don't want users to interact with in the REPL.
273+
// user contracts named console.log will be imported, and a warning will be issued.
274+
if (
275+
sources.length > 1 ||
276+
(sources.length === 1 &&
277+
!sources.some(source => {
278+
return (
279+
source === "truffle/console.sol" ||
280+
source === "truffle/Console.sol"
281+
);
282+
}))
283+
) {
284+
jsonBlobs.push(json);
285+
}
281286
}
282287
} catch (error) {
283288
throw new Error(`Error parsing or reading ${file}: ${error.message}`);

0 commit comments

Comments
 (0)