Skip to content

Commit

Permalink
fix(core/tasks): takes IScripts being an instance of Error into account
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed May 1, 2019
1 parent 55541aa commit a19b394
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/core/tasks/from-kpo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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`);
}

Expand Down
8 changes: 7 additions & 1 deletion src/core/tasks/recursive-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ export default function recursiveFields(obj: IOfType<any>): string[] {
}

export function trunk(obj: IOfType<any>, 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}`));
Expand Down

0 comments on commit a19b394

Please sign in to comment.