-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show truncated help on some errors (#1004)
* feat: show truncated help on some errors * fix: remove circular deps
- Loading branch information
1 parent
6894fb9
commit 7133a97
Showing
14 changed files
with
112 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import write from '../cli-ux/write' | ||
import {OclifError, PrettyPrintableError} from '../interfaces' | ||
import {config} from './config' | ||
import {CLIError, addOclifExitCode} from './errors/cli' | ||
import prettyPrint, {applyPrettyPrintOptions} from './errors/pretty-print' | ||
|
||
export function error(input: Error | string, options: {exit: false} & PrettyPrintableError): void | ||
export function error(input: Error | string, options?: {exit?: number} & PrettyPrintableError): never | ||
export function error(input: Error | string, options: {exit?: false | number} & PrettyPrintableError = {}): void { | ||
let err: Error & OclifError | ||
|
||
if (typeof input === 'string') { | ||
err = new CLIError(input, options) | ||
} else if (input instanceof Error) { | ||
err = addOclifExitCode(input, options) as Error & OclifError | ||
} else { | ||
throw new TypeError('first argument must be a string or instance of Error') | ||
} | ||
|
||
err = applyPrettyPrintOptions(err, options) as Error & OclifError & PrettyPrintableError | ||
|
||
if (options.exit === false) { | ||
const message = prettyPrint(err) | ||
if (message) write.stderr(message + '\n') | ||
if (config.errorLogger) config.errorLogger.log(err?.stack ?? '') | ||
} else throw err | ||
} | ||
|
||
export default error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,15 @@ | ||
import write from '../cli-ux/write' | ||
import {OclifError, PrettyPrintableError} from '../interfaces' | ||
import {config} from './config' | ||
import {CLIError, addOclifExitCode} from './errors/cli' | ||
import {ExitError} from './errors/exit' | ||
import prettyPrint, {applyPrettyPrintOptions} from './errors/pretty-print' | ||
|
||
export {PrettyPrintableError} from '../interfaces' | ||
export {config} from './config' | ||
export {error} from './error' | ||
export {CLIError} from './errors/cli' | ||
export {ExitError} from './errors/exit' | ||
export {ModuleLoadError} from './errors/module-load' | ||
export {handle} from './handle' | ||
|
||
export {Logger} from './logger' | ||
export function exit(code = 0): never { | ||
throw new ExitError(code) | ||
} | ||
|
||
export function error(input: Error | string, options: {exit: false} & PrettyPrintableError): void | ||
export function error(input: Error | string, options?: {exit?: number} & PrettyPrintableError): never | ||
export function error(input: Error | string, options: {exit?: false | number} & PrettyPrintableError = {}): void { | ||
let err: Error & OclifError | ||
|
||
if (typeof input === 'string') { | ||
err = new CLIError(input, options) | ||
} else if (input instanceof Error) { | ||
err = addOclifExitCode(input, options) as Error & OclifError | ||
} else { | ||
throw new TypeError('first argument must be a string or instance of Error') | ||
} | ||
|
||
err = applyPrettyPrintOptions(err, options) as Error & OclifError & PrettyPrintableError | ||
|
||
if (options.exit === false) { | ||
const message = prettyPrint(err) | ||
if (message) write.stderr(message + '\n') | ||
if (config.errorLogger) config.errorLogger.log(err?.stack ?? '') | ||
} else throw err | ||
} | ||
|
||
export function warn(input: Error | string): void { | ||
let err: Error & OclifError | ||
|
||
if (typeof input === 'string') { | ||
err = new CLIError.Warn(input) | ||
} else if (input instanceof Error) { | ||
err = addOclifExitCode(input) as Error & OclifError | ||
} else { | ||
throw new TypeError('first argument must be a string or instance of Error') | ||
} | ||
|
||
const message = prettyPrint(err) | ||
if (message) write.stderr(message + '\n') | ||
if (config.errorLogger) config.errorLogger.log(err?.stack ?? '') | ||
} | ||
|
||
const WARNINGS = new Set<Error | string>() | ||
export function memoizedWarn(input: Error | string): void { | ||
if (!WARNINGS.has(input)) warn(input) | ||
|
||
WARNINGS.add(input) | ||
} | ||
|
||
export {Logger} from './logger' | ||
export {warn} from './warn' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import write from '../cli-ux/write' | ||
import {OclifError} from '../interfaces' | ||
import {config} from './config' | ||
import {CLIError, addOclifExitCode} from './errors/cli' | ||
import prettyPrint from './errors/pretty-print' | ||
|
||
export function warn(input: Error | string): void { | ||
let err: Error & OclifError | ||
|
||
if (typeof input === 'string') { | ||
err = new CLIError.Warn(input) | ||
} else if (input instanceof Error) { | ||
err = addOclifExitCode(input) as Error & OclifError | ||
} else { | ||
throw new TypeError('first argument must be a string or instance of Error') | ||
} | ||
|
||
const message = prettyPrint(err) | ||
if (message) write.stderr(message + '\n') | ||
if (config.errorLogger) config.errorLogger.log(err?.stack ?? '') | ||
} | ||
|
||
const WARNINGS = new Set<Error | string>() | ||
export function memoizedWarn(input: Error | string): void { | ||
if (!WARNINGS.has(input)) warn(input) | ||
|
||
WARNINGS.add(input) | ||
} | ||
|
||
export default warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters