Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved formatted errors #48

Merged
merged 2 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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