Skip to content

Commit

Permalink
fix(models): __dirname for absolute path & exit if model doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian7843 committed Sep 7, 2021
1 parent f093a32 commit 0c4ce3f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/hargassnerTelnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@ export class HargassnerTelnet {
}

parse(data: string[]): dynamicData {
// TODO: Handle model not found
const modelString = fs.readFileSync(
`lib/model/${this.options.model}.json`,
'utf-8'
)
let modelString = ''
try {
modelString = fs.readFileSync(
`${__dirname}/../lib/model/${this.options.model}.json`,
'utf-8'
)
} catch (e) {
console.log(`Model ${this.options.model} could not be found. Exiting...`)
process.exit(1)
}

const model = JSON.parse(modelString)
return parseModel(model, data)
}
Expand Down

0 comments on commit 0c4ce3f

Please sign in to comment.