Skip to content

Commit

Permalink
Plugin misconfiguration is not a fatal error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Esser committed Dec 11, 2016
1 parent 38a3ba9 commit e65d96a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
33 changes: 16 additions & 17 deletions lib/score-manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const VError = require('verror').VError
// const VError = require('verror').VError
const extractObject = require('./extract-object')
const utils = require('./utils')
const InvalidInputError = require('./invalid-input-error')
Expand Down Expand Up @@ -224,22 +224,21 @@ class ScoreManager {
ensurePluginExists(this.plugins, pluginId)

let plugin = this.plugins[pluginId]
let [arg0, arg1] = (() => {
try {
return plugin.inputs.map(i => extractObject(blob, i))
} catch (err) {
throw new VError(err, 'Input data does not match configuration')
}
})()
let scoringFnc = getScoringFunction(plugin)
let scores = arg1.map(arg1 => {
try {
return scoringFnc(arg0, arg1, plugin.params)
} catch (err) {
return 'failure: ' + err.message
}
})
return scores
try {
// inputs: [arg0, arg1]
let [arg0, arg1] = plugin.inputs.map(i => extractObject(blob, i))
let scoringFnc = getScoringFunction(plugin)
let scores = arg1.map(arg1 => {
try {
return scoringFnc(arg0, arg1, plugin.params)
} catch (err) {
return 'failure: ' + err.message
}
})
return scores
} catch (err) {
return ['failure: input data does not match configuration: ' + err.message]
}
}

/**
Expand Down
26 changes: 22 additions & 4 deletions test/score-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ buster.testCase('ScoreManager with configuration', {
buster.assert.exception(() => {
this.manager.scoreWith('nonexistent-plugin', {})
})
},

'should rethrow a wrapped error when extractObject throws': function () {
buster.assert.exception(() => this.manager.scoreWith('plugin-a', {}))
}
},

Expand Down Expand Up @@ -258,6 +254,28 @@ buster.testCase('ScoreManager with configuration', {
buster.assert.match(result[0]['plugin-c'], /this is the error description/)
},

'should be caught and isolated on a per plugin bases': function () {
let aggregator = { combine: this.stub().returns(1.0) }
let plugA = () => 1.0
let plugB = () => 1.0

let manager = scoreManager.create({
aggregator,
plugins: {
'plugin-a': { use: plugA, inputs: ['no-attribute-here', 'tasks[]'] },
'plugin-b': { use: plugB, inputs: ['file', 'tasks[]'] }
}
})

let blob = {
file: {},
tasks: [{}]
}

let result = manager.score(blob)
buster.assert.match(result[0]['plugin-a'], /no-attribute-here/)
},

'should only pass successful scores to the aggregator': function () {
let aggregator = { combine: this.stub() }
let plugA = () => 1.0
Expand Down

0 comments on commit e65d96a

Please sign in to comment.