Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjozork committed Oct 1, 2023
1 parent 78fc944 commit 1842e2e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/Library/Tasks/ExecTask.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { exec } from 'child_process';
import GenericTask from './GenericTask';
import { TaskStatus } from '../Contracts/Task';
import ExecTaskError from './ExecTaskError';

export default class ExecTask extends GenericTask {
constructor(
Expand All @@ -26,11 +27,7 @@ export default class ExecTask extends GenericTask {
if (code === 0) {
resolve(code);
} else {
const err = new Error();

(err as any).stderr = stderr;

reject(err);
reject(new ExecTaskError(stderr));
}
});
}));
Expand Down
5 changes: 5 additions & 0 deletions src/Library/Tasks/ExecTaskError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default class ExecTaskError extends Error {
constructor(public readonly stderr: string) {
super('Error in ExecTask spawned process');
}
}
11 changes: 9 additions & 2 deletions src/Library/Tasks/GenericTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import chalk from 'chalk';
import { TaskRunner, Task, TaskStatus } from '../Contracts/Task';
import { generateHashFromPaths, storage } from '../../Helpers';
import { Context } from '../Contracts/Context';
import ExecTaskError from './ExecTaskError';

export default class GenericTask implements Task {
protected context: Context;
Expand Down Expand Up @@ -50,9 +51,15 @@ export default class GenericTask implements Task {
this.context.cache.set(taskKey, generateHash);
}
} catch (error) {
if (this.context.debug) throw error;
if (this.context.debug) {
throw error;
}

this.status = TaskStatus.Failed;
if ('stderr' in error) this.errorOutput = error.stderr;

if (error instanceof ExecTaskError) {
this.errorOutput = error.stderr;
}
}
}

Expand Down

0 comments on commit 1842e2e

Please sign in to comment.