From 6a52bcace3602cb99bc7b2f874be8bad585461ee Mon Sep 17 00:00:00 2001 From: Dhruv Srivastava Date: Tue, 4 Apr 2023 15:08:53 +0530 Subject: [PATCH] Log solc compilation errors --- packages/codegen/src/artifacts.ts | 13 ++++++++++++- packages/codegen/src/generate-code.ts | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/codegen/src/artifacts.ts b/packages/codegen/src/artifacts.ts index d23b989f1..dda36e438 100644 --- a/packages/codegen/src/artifacts.ts +++ b/packages/codegen/src/artifacts.ts @@ -32,9 +32,20 @@ export async function generateArtifacts (contractContent: string, contractFileNa }; const solcInstance = (solcVersion === undefined) ? solc : await getSolcByVersion(solcVersion); + const compiledContract = JSON.parse(solcInstance.compile(JSON.stringify(input))); + + if (compiledContract.errors?.length) { + compiledContract.errors.forEach((error: any) => { + if (error.severity === 'error') { + throw new Error(error.formattedMessage); + } + + console.log(`${error.severity}: ${error.formattedMessage}`); + }); + } // Get artifacts for the required contract. - return JSON.parse(solcInstance.compile(JSON.stringify(input))).contracts[contractFileName][contractName]; + return compiledContract.contracts[contractFileName][contractName]; } async function getSolcByVersion (solcVersion: string): Promise { diff --git a/packages/codegen/src/generate-code.ts b/packages/codegen/src/generate-code.ts index cadc3f3d8..74ac5f4fb 100644 --- a/packages/codegen/src/generate-code.ts +++ b/packages/codegen/src/generate-code.ts @@ -48,7 +48,7 @@ const main = async (): Promise => { type: 'string' }) .option('continue-on-error', { - alias: 'C', + alias: 'e', demandOption: false, default: false, describe: 'Continue generating watcher if unhandled types encountered',