diff --git a/src/core/tasks/from-kpo.ts b/src/core/tasks/from-kpo.ts index c72ec72..56a752f 100644 --- a/src/core/tasks/from-kpo.ts +++ b/src/core/tasks/from-kpo.ts @@ -1,6 +1,7 @@ import { ITask } from '../types'; import { IScripts } from '~/types'; import purePath from './pure-path'; +import { CustomError } from '~/utils/errors'; export default function getFromKpo(path: string, kpo: IScripts): ITask { const task = trunk(purePath(path).split('.'), kpo, ''); @@ -41,8 +42,9 @@ export function trunk(arr: string[], obj: any, path: string): ITask { ); } if (!props.length) { - throw Error( - `There are no tasks matching ${purePath(path ? `${path}.${key}` : key)}` + throw new CustomError( + `There are no tasks matching ${purePath(path ? `${path}.${key}` : key)}`, + { type: 'NotFound' } ); } const actualKey = props.shift() as string; diff --git a/src/core/tasks/index.ts b/src/core/tasks/index.ts index 94b8212..b9c11fa 100644 --- a/src/core/tasks/index.ts +++ b/src/core/tasks/index.ts @@ -3,6 +3,7 @@ import getFromKpo from './from-kpo'; import getFromPackage from './from-package'; import { ITask, ITasks } from '../types'; import recursiveFields from './recursive-fields'; +import { CustomError } from '~/utils/errors'; export function getTask( path: string, @@ -11,9 +12,11 @@ export function getTask( ): ITask { try { if (kpo) return getFromKpo(path, kpo); - throw Error(`Task ${path} not found`); + throw new CustomError(`Task ${path} not found`, { type: 'NotFound' }); } catch (err) { - if (!pkg) throw err; + if (!pkg || !err.data || !err.data.type || err.data.type !== 'NotFound') { + throw err; + } try { return getFromPackage(path, pkg);