Skip to content

Commit

Permalink
fix: poor exception behavior with odd null error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
starpit committed Feb 17, 2023
1 parent e94533f commit 120bc8c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/core/command-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ const withEvents = <T extends KResponse, O extends ParsedOptions>(
}
}

if (err.code === 127 && partialMatches) {
if (err && err.code === 127 && partialMatches) {
// command not found
const suggestions = suggestPartialMatches(command, partialMatches, true, err.hide) // true: don't throw an exception
return suggestions
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/core/oops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

/* eslint-disable no-use-before-define */

interface ErrorWithResultField {
error: {
response: {
Expand Down Expand Up @@ -89,6 +91,8 @@ export const oopsMessage = (err: ErrorLike): string => {
try {
if (typeof err === 'string') {
return err
} else if (typeof err === 'undefined') {
return ''
} else if (isErrorWithNestedResultField(err)) {
return err.error.response.result.error.error // feed creation error. nice
} else if (isErrorWithResultField(err)) {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/main/headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ const success = (quit: QuitFunction) => async (out: Entity | Promise<Entity>) =>
const failure = (quit: QuitFunction, execOptions?: ExecOptions) => async (err: CodedError) => {
if (execOptions && execOptions.rethrowErrors) {
throw err
} else if (!err) {
return
}

const code = err.code || err.statusCode
Expand Down

0 comments on commit 120bc8c

Please sign in to comment.