diff --git a/src/errors/errors/cli.ts b/src/errors/errors/cli.ts index 46473ac6e..3a428ea8c 100644 --- a/src/errors/errors/cli.ts +++ b/src/errors/errors/cli.ts @@ -6,16 +6,11 @@ import Indent = require('indent-string') import * as Wrap from 'wrap-ansi' import {config} from '../config' -import {PrettyPrintableError} from './pretty-print' +import {PrettyPrintableError, OclifError} from '../../interfaces/errors' /** * properties specific to internal oclif error handling */ -export interface OclifError { - oclif: { - exit?: number | false; - }; -} export function addOclifExitCode(error: Record, options?: { exit?: number | false }): OclifError { if (!('oclif' in error)) { diff --git a/src/errors/errors/exit.ts b/src/errors/errors/exit.ts index 790e37459..eeb7c3164 100644 --- a/src/errors/errors/exit.ts +++ b/src/errors/errors/exit.ts @@ -1,4 +1,5 @@ -import {CLIError, OclifError} from './cli' +import {CLIError} from './cli' +import {OclifError} from '../../interfaces' export class ExitError extends CLIError implements OclifError { oclif!: { exit: number } diff --git a/src/errors/errors/pretty-print.ts b/src/errors/errors/pretty-print.ts index e1de26df7..379ead835 100644 --- a/src/errors/errors/pretty-print.ts +++ b/src/errors/errors/pretty-print.ts @@ -1,30 +1,9 @@ import * as wrap from 'wrap-ansi' import indent = require('indent-string') + import * as screen from '../screen' import {config} from '../config' - -export interface PrettyPrintableError { - /** - * messsage to display related to the error - */ - message?: string; - - /** - * a unique error code for this error class - */ - code?: string; - - /** - * a url to find out more information related to this error - * or fixing the error - */ - ref?: string; - - /** - * a suggestion that may be useful or provide additional context - */ - suggestions?: string[]; -} +import {PrettyPrintableError} from '../../interfaces/errors' // These exist for backwards compatibility with CLIError type CLIErrorDisplayOptions = { name?: string; bang?: string } diff --git a/src/errors/handle.ts b/src/errors/handle.ts index b7430eabb..0e09276a8 100644 --- a/src/errors/handle.ts +++ b/src/errors/handle.ts @@ -1,10 +1,11 @@ /* eslint-disable no-process-exit */ /* eslint-disable unicorn/no-process-exit */ import {config} from './config' -import prettyPrint, {PrettyPrintableError} from './errors/pretty-print' +import prettyPrint from './errors/pretty-print' import {ExitError} from '.' import clean = require('clean-stack') -import {OclifError, CLIError} from './errors/cli' +import {CLIError} from './errors/cli' +import {OclifError, PrettyPrintableError} from '../interfaces' export const handle = (err: Error & Partial & Partial) => { try { diff --git a/src/errors/index.ts b/src/errors/index.ts index d3e92298d..2470f3dac 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -7,9 +7,10 @@ export {Logger} from './logger' export {config} from './config' import {config} from './config' -import {CLIError, addOclifExitCode, OclifError} from './errors/cli' +import {CLIError, addOclifExitCode} from './errors/cli' import {ExitError} from './errors/exit' -import prettyPrint, {PrettyPrintableError, applyPrettyPrintOptions} from './errors/pretty-print' +import prettyPrint, {applyPrettyPrintOptions} from './errors/pretty-print' +import {OclifError, PrettyPrintableError} from '../interfaces' export {PrettyPrintableError} diff --git a/src/interfaces/errors.ts b/src/interfaces/errors.ts new file mode 100644 index 000000000..6046051a6 --- /dev/null +++ b/src/interfaces/errors.ts @@ -0,0 +1,28 @@ +export interface OclifError { + oclif: { + exit?: number | false; + }; +} + +export interface PrettyPrintableError { + /** + * messsage to display related to the error + */ + message?: string; + + /** + * a unique error code for this error class + */ + code?: string; + + /** + * a url to find out more information related to this error + * or fixing the error + */ + ref?: string; + + /** + * a suggestion that may be useful or provide additional context + */ + suggestions?: string[]; +} diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index 1d1ce08c2..a3d54c684 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -1,5 +1,6 @@ export {Config, ArchTypes, PlatformTypes, LoadOptions} from './config' export {Command} from './command' +export {OclifError, PrettyPrintableError} from './errors' export {Hook, HookKeyOrOptions, Hooks} from './hooks' export {Manifest} from './manifest' export {PJSON} from './pjson' diff --git a/test/errors/error.test.ts b/test/errors/error.test.ts index aa58a3ab8..15ab20a52 100644 --- a/test/errors/error.test.ts +++ b/test/errors/error.test.ts @@ -1,6 +1,6 @@ import {expect, fancy} from 'fancy-test' import {error} from '../../src/errors' -import {PrettyPrintableError} from '../../src/errors/errors/pretty-print' +import {PrettyPrintableError} from '../../src/interfaces/errors' describe('error', () => { fancy diff --git a/test/errors/pretty-print.test.ts b/test/errors/pretty-print.test.ts index 4831a0d3b..831336821 100644 --- a/test/errors/pretty-print.test.ts +++ b/test/errors/pretty-print.test.ts @@ -1,5 +1,6 @@ import {expect, fancy} from 'fancy-test' -import prettyPrint, {PrettyPrintableError} from '../../src/errors/errors/pretty-print' +import prettyPrint from '../../src/errors/errors/pretty-print' +import {PrettyPrintableError} from '../../src/interfaces/errors' import {CLIError} from '../../src/errors' import {config} from '../../src/errors/config' const stripAnsi = require('strip-ansi')