diff --git a/src/core/tasks/from-kpo.ts b/src/core/tasks/from-kpo.ts index e43b60c..6be2b7c 100644 --- a/src/core/tasks/from-kpo.ts +++ b/src/core/tasks/from-kpo.ts @@ -9,7 +9,12 @@ export default function getFromKpo(path: string, kpo: IScripts): ITask { export function trunk(arr: string[], obj: any, path: string): ITask { if (!arr.length) { - if (typeof obj === 'object' && !Array.isArray(obj) && obj !== null) { + if ( + typeof obj === 'object' && + !Array.isArray(obj) && + obj !== null && + !(obj instanceof Error) + ) { const task = trunk(['default'], obj, path); if (obj.hasOwnProperty('_description')) { if (task.hasOwnProperty('description')) { @@ -23,7 +28,7 @@ export function trunk(arr: string[], obj: any, path: string): ITask { } const key = arr.shift() as string; - if (typeof obj !== 'object' || obj === null) { + if (typeof obj !== 'object' || obj === null || obj instanceof Error) { throw Error(`${path} is not an object`); } diff --git a/src/core/tasks/recursive-fields.ts b/src/core/tasks/recursive-fields.ts index 30f0170..c86c138 100644 --- a/src/core/tasks/recursive-fields.ts +++ b/src/core/tasks/recursive-fields.ts @@ -6,9 +6,15 @@ export default function recursiveFields(obj: IOfType): string[] { } export function trunk(obj: IOfType, path: string): string[] { - if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) { + if ( + typeof obj !== 'object' || + obj === null || + obj instanceof Error || + Array.isArray(obj) + ) { return [path]; } + return Object.entries(obj).reduce((acc: string[], [key, value]) => { if (key[0] === '_') return acc; acc = acc.concat(trunk(value, `${path}.${key}`));