Skip to content

Commit

Permalink
feat: export OclifError & PrettyPrintableError in Interfaces (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
RasPhilCo committed Sep 16, 2020
1 parent 187f5b8 commit 766b6f5
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 36 deletions.
7 changes: 1 addition & 6 deletions src/errors/errors/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>, options?: { exit?: number | false }): OclifError {
if (!('oclif' in error)) {
Expand Down
3 changes: 2 additions & 1 deletion src/errors/errors/exit.ts
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
25 changes: 2 additions & 23 deletions src/errors/errors/pretty-print.ts
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
5 changes: 3 additions & 2 deletions src/errors/handle.ts
Original file line number Diff line number Diff line change
@@ -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<PrettyPrintableError> & Partial<OclifError>) => {
try {
Expand Down
5 changes: 3 additions & 2 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
28 changes: 28 additions & 0 deletions src/interfaces/errors.ts
Original file line number Diff line number Diff line change
@@ -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[];
}
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion test/errors/error.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/errors/pretty-print.test.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down

0 comments on commit 766b6f5

Please sign in to comment.