Skip to content

Commit

Permalink
Truffle flattener cyclic dependencies error - re-work on PR #844 (#857)
Browse files Browse the repository at this point in the history
* Show a detailed error with next steps when cyclic dependencies are found

* Add error handler on contract  deployment task

* Unified truffle flattener cyclic dependency errors

* Add return and array to flatten call
  • Loading branch information
eternauta1337 authored and macor161 committed Oct 31, 2019
1 parent cc370b9 commit 2de4416
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs')
const path = require('path')
const { readJson, writeJson } = require('fs-extra')
const flatten = require('truffle-flattener')
const flattenCode = require('../../../helpers/flattenCode')
const extract = require('../../../helpers/solidity-extractor')
const namehash = require('eth-ens-namehash')
const taskInput = require('listr-input')
Expand Down Expand Up @@ -152,7 +152,7 @@ async function generateApplicationArtifact(
}

async function generateFlattenedCode(dir, sourcePath) {
const flattenedCode = await flatten([sourcePath])
const flattenedCode = await flattenCode([sourcePath])
fs.writeFileSync(path.resolve(dir, SOLIDITY_FILE), flattenedCode)
}

Expand Down
22 changes: 22 additions & 0 deletions packages/aragon-cli/src/helpers/flattenCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const flatten = require('truffle-flattener')

module.exports = async (sourcePaths) => {
try {
return flatten(sourcePaths)
} catch (error) {
const cycleDependencyErrorDetected = /cycle.+dependency/.test(error.message)
if (cycleDependencyErrorDetected) {
throw Error(`Cyclic dependencies in .sol files are not supported.
'truffle-flattener' requires all cyclic dependencies to be resolved before proceeding.
To do so, you can:
- Remove unnecessary import statements, if any
- Abstract the interface of imported contracts in a separate file
- Merge multiple contracts in a single .sol file
Original error: ${error}
`)
} else {
throw error
}
}
}
5 changes: 3 additions & 2 deletions packages/aragon-cli/src/helpers/truffle-deploy-artifacts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const flatten = require('truffle-flattener')
const flattenCode = require('../helpers/flattenCode')
const { getTruffleConfig } = require('./truffle-config')

module.exports = async contractArtifacts => {
Expand All @@ -11,7 +11,8 @@ module.exports = async contractArtifacts => {

const solcConfig = getTruffleConfig().solc
compiler.optimizer = solcConfig ? solcConfig.optimizer : { enabled: false }
const flattenedCode = await flatten([sourcePath])

const flattenedCode = await flattenCode([sourcePath])

return {
contractName,
Expand Down

0 comments on commit 2de4416

Please sign in to comment.