From 7bebcb787155b2d1a45f9271ae0e774db4ebbf56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Sat, 23 Jan 2021 15:46:54 +0100 Subject: [PATCH] prepare_report.js: Print ERROR in case of an exception during compilation instead of failing - Our v0.4.11 release raises an exception on some LLL snippets containing returnlll (extracted from its end-to-end tests). - The report comparison will fail anyway because emscripten prints an abort code to stdout in that case but at least we'll be able to continue if we're comparing multiple versions. --- scripts/bytecodecompare/prepare_report.js | 40 +++++++++++++++-------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/scripts/bytecodecompare/prepare_report.js b/scripts/bytecodecompare/prepare_report.js index b8e8821fa..608337c86 100755 --- a/scripts/bytecodecompare/prepare_report.js +++ b/scripts/bytecodecompare/prepare_report.js @@ -52,27 +52,41 @@ for (const optimize of [false, true]) if (!stripSMTPragmas) input['settings']['modelChecker'] = {engine: 'none'} - const result = JSON.parse(compiler.compile(JSON.stringify(input))) + let serializedOutput + let result + const serializedInput = JSON.stringify(input) let internalCompilerError = false - if ('errors' in result) + try { - for (const error of result['errors']) - // JSON interface still returns contract metadata in case of an internal compiler error while - // CLI interface does not. To make reports comparable we must force this case to be detected as - // an error in both cases. - if (['UnimplementedFeatureError', 'CompilerError', 'CodeGenerationError'].includes(error['type'])) - { - internalCompilerError = true - break - } + serializedOutput = compiler.compile(serializedInput) + } + catch (exception) + { + internalCompilerError = true + } + + if (!internalCompilerError) + { + result = JSON.parse(serializedOutput) + + if ('errors' in result) + for (const error of result['errors']) + // JSON interface still returns contract metadata in case of an internal compiler error while + // CLI interface does not. To make reports comparable we must force this case to be detected as + // an error in both cases. + if (['UnimplementedFeatureError', 'CompilerError', 'CodeGenerationError'].includes(error['type'])) + { + internalCompilerError = true + break + } } if ( + internalCompilerError || !('contracts' in result) || Object.keys(result['contracts']).length === 0 || - Object.keys(result['contracts']).every(file => Object.keys(result['contracts'][file]).length === 0) || - internalCompilerError + Object.keys(result['contracts']).every(file => Object.keys(result['contracts'][file]).length === 0) ) // NOTE: do not exit here because this may be run on source which cannot be compiled console.log(filename + ': ')