Commit 37b83eaf authored by yann300's avatar yann300 Committed by Aniket

add type for compilation error

parent 755ee4af
...@@ -2,7 +2,7 @@ import fs from './fileSystem' ...@@ -2,7 +2,7 @@ import fs from './fileSystem'
import async from 'async' import async from 'async'
import path from 'path' import path from 'path'
let RemixCompiler = require('remix-solidity').Compiler let RemixCompiler = require('remix-solidity').Compiler
import { SrcIfc, CompilerConfiguration } from './types' import { SrcIfc, CompilerConfiguration, CompilationErrors } from './types'
function regexIndexOf (inputString: string, regex: RegExp, startpos: number = 0) { function regexIndexOf (inputString: string, regex: RegExp, startpos: number = 0) {
const indexOf = inputString.substring(startpos).search(regex) const indexOf = inputString.substring(startpos).search(regex)
...@@ -132,7 +132,7 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: ...@@ -132,7 +132,7 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts:
let errors = (result.errors || error).filter((e) => e.type === 'Error' || e.severity === 'error') let errors = (result.errors || error).filter((e) => e.type === 'Error' || e.severity === 'error')
if (errors.length > 0) { if (errors.length > 0) {
if (!isBrowser) require('signale').fatal(errors) if (!isBrowser) require('signale').fatal(errors)
return cb(errors) return cb(new CompilationErrors(errors))
} }
cb(err, result.contracts, result.sources) //return callback with contract details & ASTs cb(err, result.contracts, result.sources) //return callback with contract details & ASTs
}) })
...@@ -191,7 +191,7 @@ export function compileContractSources(sources: SrcIfc, compilerConfig: Compiler ...@@ -191,7 +191,7 @@ export function compileContractSources(sources: SrcIfc, compilerConfig: Compiler
let errors = (result.errors || error).filter((e) => e.type === 'Error' || e.severity === 'error') let errors = (result.errors || error).filter((e) => e.type === 'Error' || e.severity === 'error')
if (errors.length > 0) { if (errors.length > 0) {
if (!isBrowser) require('signale').fatal(errors) if (!isBrowser) require('signale').fatal(errors)
return cb(errors) return cb(new CompilationErrors(errors))
} }
cb(err, result.contracts, result.sources) // return callback with contract details & ASTs cb(err, result.contracts, result.sources) // return callback with contract details & ASTs
}) })
......
...@@ -51,6 +51,21 @@ export interface CompilerConfiguration { ...@@ -51,6 +51,21 @@ export interface CompilerConfiguration {
usingWorker: boolean usingWorker: boolean
} }
export interface CompilationErrors {
name: string,
errors: Array<Error>,
message: string
}
export class CompilationErrors extends Error {
constructor(errors) {
const mapError = errors.map((e) => { return e.formattedMessage || e.message })
super(mapError.join('\n'))
this.errors = errors
this.name = 'CompilationErrors'
}
}
/** sources object with name of the file and content **/ /** sources object with name of the file and content **/
//////////// ////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment