Skip to content

Commit

Permalink
Merge pull request #48 from macor161/improved-formatted-errors
Browse files Browse the repository at this point in the history
Improved formatted errors
  • Loading branch information
macor161 authored Jun 18, 2019
2 parents 7775fde + eec56de commit 8150390
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/compiler/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
22 changes: 15 additions & 7 deletions src/detailederror.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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,
Expand Down Expand Up @@ -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')
}
}
2 changes: 1 addition & 1 deletion src/quantal-compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down

0 comments on commit 8150390

Please sign in to comment.