diff --git a/README.md b/README.md index ade465f..7b6838b 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,9 @@ The following truffle config options are currently supported: * The current alpha version is not recommended for production use. * Windows is currently not supported -* Some solc versions are not supported yet. See list below +* Some solc versions are not supported yet. See list below. * Cache is not implemented yet. This means quantal will recompile all smart contracts every time it’s launched. Cache support is coming soon. +* Formatted error messages are not supported for solc versions below 0.4.20 ## Supported solc versions diff --git a/src/compiler/worker.js b/src/compiler/worker.js index 850d31c..c334f01 100644 --- a/src/compiler/worker.js +++ b/src/compiler/worker.js @@ -47,6 +47,11 @@ module.exports = class Worker { this._debug(`time ${new Date().toISOString()}`) const result = await this._sendInputToProcess() + + for (const path in result.sources) { + result.sources[path].source = this.input.sources[path] && this.input.sources[path].content + } + this._debug('compile done') return result } diff --git a/src/detailederror.js b/src/detailederror.js index 2e62de5..5c42161 100644 --- a/src/detailederror.js +++ b/src/detailederror.js @@ -1,5 +1,5 @@ const lineColumn = require('line-column') -const {isObject, range} = require('lodash') +const {isObject, range, get} = require('lodash') const {promisify} = require('util') const {isAbsolute} = require('path') const fs = require('fs') @@ -10,14 +10,15 @@ const LINES_OF_CONTEXT = 6 /** * Add details to a CompilerOutputError object */ -module.exports = async function detailedCompilerOutputError(compilerOutputError) { +module.exports = async function detailedCompilerOutputError(compilerOutputError, compileResult) { try { - if (!compilerOutputError.sourceLocation || !isAbsolute(compilerOutputError.sourceLocation.file)) { - return compilerOutputError - } + + const fileContent = get(compileResult, 'source') + ? compileResult.source + : await getSource(compilerOutputError) - const fileContent = await readFile(compilerOutputError.sourceLocation.file, 'utf-8') - // console.log(fileContent) + if (!fileContent) + return compilerOutputError const error = { ...compilerOutputError, @@ -56,3 +57,10 @@ function addSourceContext(error, fileContent) { .reduce((acc, line) => ({...acc, [line]: lines[line - 1]}), {}), } } + + +function getSource(compilerOutputError) { + if (compilerOutputError.sourceLocation && isAbsolute(compilerOutputError.sourceLocation.file)) { + return readFile(compilerOutputError.sourceLocation.file, 'utf-8') + } +} diff --git a/src/quantal-compile.js b/src/quantal-compile.js index 56e795d..7194eed 100644 --- a/src/quantal-compile.js +++ b/src/quantal-compile.js @@ -259,7 +259,7 @@ const compile = function(sources, options, callback) { const compilerInfo = {name: 'solc', version: getFormattedVersion(solcVersion)}; - Promise.all(warnings.map((warn) => detailedError(warn))) + Promise.all(warnings.map((warn) => detailedError(warn, standardOutput.sources[_.get(warn, ['sourceLocation', 'file'])]))) .then((warnings) => callback(null, returnVal, files, compilerInfo, warnings)) }