Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 5c2ddd0

Browse files
author
Jonathan Spruance (Insight Global)
committed
Throw CLIError directly from read file util
1 parent 426ee25 commit 5c2ddd0

2 files changed

Lines changed: 11 additions & 20 deletions

File tree

packages/chatdown/src/commands/chatdown.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,17 @@ export default class Chatdown extends Command {
7777
}
7878

7979
private async getInput(args: any) {
80-
try {
81-
// Check if path passed in --in
82-
if (args && args.length > 0) {
83-
return utils.readTextFile(args)
84-
} else {
85-
//Check if piped data was sent
86-
const {stdin} = process
87-
if (stdin.isTTY) {
88-
return false
89-
} else {
90-
return await this.readStdin()
91-
}
92-
}
93-
} catch (err) {
94-
if (err.message.match(/no such file or directory/)) {
95-
throw new CLIError(err.message)
96-
}
97-
if (err.message.match(/No Input/)) {
80+
// Check if path passed in --in
81+
if (args && args.length > 0) {
82+
return utils.readTextFile(args)
83+
} else {
84+
//Check if piped data was sent
85+
const {stdin} = process
86+
if (stdin.isTTY) {
9887
return false
88+
} else {
89+
return this.readStdin()
9990
}
100-
throw err
10191
}
10292
}
10393

packages/command/src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require('fs-extra')
2+
import { CLIError } from '@oclif/errors'
23

34
const utils = {
45
readTextFile: async (file: any) => {
@@ -46,7 +47,7 @@ const utils = {
4647
return resolve(fileBuffer.toString('utf8').replace(/\0/g, ''))
4748
} catch (err) {
4849
if (err.message.match(/ENOENT: no such file or directory/)) {
49-
return reject(err)
50+
return reject(new CLIError(err.message))
5051
}
5152
return reject(
5253
`Invalid Input. Sorry, unable to parse file: \n\n ${JSON.stringify(err, null, 2)}\n\n`)

0 commit comments

Comments
 (0)