Skip to content

Commit

Permalink
feat: describe task name
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Nov 26, 2020
1 parent 8b93892 commit ff3b10d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,26 @@ Planton produces 2 types of errors:

Produced when Planton is initiated with non-unique task names.

`duplicateTaskName` error property describes the offending task name.
Additional error properties:

* `duplicateTaskName` describes the offending task name.

#### `InvalidTaskConfigurationNameError`

Produced when Planton is initiated with invalid configuration, e.g. `concurrency` value less than 1.

Additional error properties:

* `taskName`

#### `UnexpectedTaskInstructionsError`

Produced when task scheduler produces a result that is not an array or members of array are not strings.

`unexpectedTaskInstructions` error property describes the offending instructions.
Additional error properties:

* `taskName`
* `unexpectedTaskInstructions` describes the offending instructions.

Tip: [Inspect logs](#inspecting-logs) for additional details.

Expand Down
11 changes: 9 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ export class UnexpectedStateError extends PlantonError {
}

export class InvalidTaskConfigurationNameError extends UnexpectedStateError {
constructor (message: string) {
taskName: string;

constructor (taskName: string, message: string) {
super(
message,
'INVALID_TASK_CONFIGURATION',
);

this.taskName = taskName;
}
}

Expand All @@ -39,14 +43,17 @@ export class DuplicateTaskNameError extends UnexpectedStateError {
}

export class UnexpectedTaskInstructionsError extends UnexpectedStateError {
taskName: string;

unexpectedTaskInstructions: any;

constructor (unexpectedTaskInstructions: any) {
constructor (taskName: string, unexpectedTaskInstructions: any) {
super(
'Unexpected task instructions.',
'UNEXPECTED_TASK_INSTRUCTIONS',
);

this.taskName = taskName;
this.unexpectedTaskInstructions = unexpectedTaskInstructions;
}
}
8 changes: 4 additions & 4 deletions src/factories/createPlanton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const createPlanton = (configuration: PlantonConfiguration): Planton => {
const concurrency = inputTask.concurrency === undefined ? 1 : inputTask.concurrency;

if (concurrency < 1) {
throw new InvalidTaskConfigurationNameError('Task concurrency must be greater than 0.');
throw new InvalidTaskConfigurationNameError(inputTask.name, 'Task concurrency must be greater than 0.');
}

const task: Partial<InternalTask> = {
Expand Down Expand Up @@ -166,7 +166,7 @@ const createPlanton = (configuration: PlantonConfiguration): Planton => {

if (!Array.isArray(taskInstructions)) {
events.emit('error', {
error: new UnexpectedTaskInstructionsError(taskInstructions),
error: new UnexpectedTaskInstructionsError(task.name, taskInstructions),
taskName: task.name || '',
});

Expand All @@ -180,7 +180,7 @@ const createPlanton = (configuration: PlantonConfiguration): Planton => {

if (taskInstructions.length > limit) {
events.emit('error', {
error: new UnexpectedTaskInstructionsError(taskInstructions),
error: new UnexpectedTaskInstructionsError(task.name, taskInstructions),
taskName: task.name || '',
});

Expand All @@ -197,7 +197,7 @@ const createPlanton = (configuration: PlantonConfiguration): Planton => {
for (const taskInstruction of taskInstructions) {
if (typeof taskInstruction !== 'string') {
events.emit('error', {
error: new UnexpectedTaskInstructionsError(taskInstructions),
error: new UnexpectedTaskInstructionsError(task.name, taskInstructions),
taskName: task.name || '',
});

Expand Down

0 comments on commit ff3b10d

Please sign in to comment.