Skip to content

Commit

Permalink
feat: throw if there's missing mandatory config keys
Browse files Browse the repository at this point in the history
  • Loading branch information
slvnperron committed Apr 29, 2018
1 parent 59c581a commit 7635b27
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/core/botpress/src/config-manager/module.js
@@ -1,5 +1,6 @@
import path from 'path'
import fs from 'fs'
import _ from 'lodash'

export default class ModuleConfiguration {
constructor(options) {
Expand Down Expand Up @@ -33,7 +34,21 @@ export default class ModuleConfiguration {
}

async loadAll(caching = true) {
return this.manager.loadAll(this._getFileName(), this._getOptions(), caching)
const config = await this.manager.loadAll(this._getFileName(), this._getOptions(), caching)

const file = this._getFileName()
const filePath = path.resolve(this.configLocation, file)

_.mapValues(config, (value, key) => {
if (value === '<<UPDATE_ME>>') {
const message = `[${this.module.name}] Missing mandatory configuration for "${key}".
You can provide this value in "${filePath}"`
this.logger.error(message)
throw new Error(message)
}
})

return config
}

async get(key, caching = true) {
Expand Down Expand Up @@ -64,8 +79,6 @@ export default class ModuleConfiguration {
async isConfigMissing() {
const file = this._getFileName()
const filePath = path.resolve(this.configLocation, file)

console.log(this._hasDefaultConfig(), filePath)
return this._hasDefaultConfig() && !fs.existsSync(filePath)
}
}

0 comments on commit 7635b27

Please sign in to comment.