Skip to content

Commit

Permalink
voting: catch invalid script error (#884)
Browse files Browse the repository at this point in the history
* voting: catch invalid script error

* Use console.error
  • Loading branch information
2color committed Jun 6, 2019
1 parent 7d61235 commit 51e4800
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions apps/voting/app/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,25 @@ async function loadVoteDescription(vote) {
return vote
}

const path = await app.describeScript(vote.script).toPromise()
vote.description = path
? path
.map(step => {
const identifier = step.identifier ? ` (${step.identifier})` : ''
const app = step.name ? `${step.name}${identifier}` : `${step.to}`

return `${app}: ${step.description || 'No description'}`
})
.join('\n')
: ''
try {
const path = await app.describeScript(vote.script).toPromise()

vote.description = path
? path
.map(step => {
const identifier = step.identifier ? ` (${step.identifier})` : ''
const app = step.name ? `${step.name}${identifier}` : `${step.to}`

return `${app}: ${step.description || 'No description'}`
})
.join('\n')
: ''
} catch (error) {
console.error('Error describing vote script', error)
vote.description = 'Invalid script. The result cannot be executed.'
// Clear metadata so ensure it's rendered with a description rather than question
vote.metadata = null
}

return vote
}
Expand Down

0 comments on commit 51e4800

Please sign in to comment.