Skip to content

Commit

Permalink
feat(errors): adds CustomError and WrappedError
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 23, 2019
1 parent 78d5fd7 commit 06e7010
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/bin/kpo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import main from './main';
import state from '~/state';
import { error } from 'cli-belt';
import logger from '~/utils/logger';
import { OpenError } from '~/utils/open';
import { OpenError } from '~/utils/errors';

main(process.argv.slice(2)).catch((err) => {
const isOpen = err instanceof OpenError;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/run/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import logger from '~/utils/logger';
import chalk from 'chalk';
import retrieveTask from './retrieve';
import exec from '~/utils/exec';
import open from '~/utils/open';
import { open } from '~/utils/errors';

export default async function runTask(
name: string,
Expand Down
2 changes: 1 addition & 1 deletion src/state/load/read-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import yaml from 'js-yaml';
import { IScripts } from '~/types';
import { rejects } from 'errorish';
import open from '~/utils/open';
import { open } from '~/utils/errors';

export default async function readFile(file: string): Promise<IScripts> {
const { ext } = path.parse(file);
Expand Down
17 changes: 17 additions & 0 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { scope, Errorish } from 'errorish';

export class CustomError<T> extends Errorish<T> {}

export class OpenError<T> extends CustomError<T> {}

export const open = scope.set('_kpo_open_', {
Error: CustomError,
Errorish: OpenError
});

export class WrappedError<T> extends CustomError<T> {}

export const wrap = scope.set('_kpo_wrap_', {
Error: CustomError,
Errorish: WrappedError
});
8 changes: 0 additions & 8 deletions src/utils/open.ts

This file was deleted.

0 comments on commit 06e7010

Please sign in to comment.