BREAKING CHANGE(taskbuffer): Change default Task error handling: trigger() now rejects when taskFunction throws; add catchErrors option (default false) to preserve previous swallow behavior; track errors (lastError, errorCount) and expose them in metadata; improve error propagation and logging across runners, chains, parallels and debounced tasks; add tests and documentation for new behavior.
This commit is contained in:
@@ -27,18 +27,20 @@ export class Taskchain extends Task {
|
||||
let taskCounter = 0; // counter for iterating async over the taskArray
|
||||
const iterateTasks = (x: any) => {
|
||||
if (typeof this.taskArray[taskCounter] !== 'undefined') {
|
||||
console.log(
|
||||
this.name + ' running: Task' + this.taskArray[taskCounter].name,
|
||||
);
|
||||
logger.log('info', `${this.name} running: Task ${this.taskArray[taskCounter].name}`);
|
||||
this.taskArray[taskCounter].trigger(x).then((x) => {
|
||||
logger.log('info', this.taskArray[taskCounter].name);
|
||||
taskCounter++;
|
||||
iterateTasks(x);
|
||||
}).catch((err) => {
|
||||
const chainError = new Error(
|
||||
`Taskchain "${this.name}": task "${this.taskArray[taskCounter].name || 'unnamed'}" (index ${taskCounter}) failed: ${err instanceof Error ? err.message : String(err)}`
|
||||
);
|
||||
(chainError as any).cause = err;
|
||||
done.reject(chainError);
|
||||
});
|
||||
} else {
|
||||
console.log(
|
||||
'Taskchain "' + this.name + '" completed successfully',
|
||||
);
|
||||
logger.log('info', `Taskchain "${this.name}" completed successfully`);
|
||||
done.resolve(x);
|
||||
}
|
||||
};
|
||||
@@ -53,10 +55,15 @@ export class Taskchain extends Task {
|
||||
addTask(taskArg: Task) {
|
||||
this.taskArray.push(taskArg);
|
||||
}
|
||||
removeTask(taskArg: Task) {
|
||||
// TODO:
|
||||
removeTask(taskArg: Task): boolean {
|
||||
const index = this.taskArray.indexOf(taskArg);
|
||||
if (index === -1) {
|
||||
return false;
|
||||
}
|
||||
this.taskArray.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
shiftTask() {
|
||||
// TODO:
|
||||
shiftTask(): Task | undefined {
|
||||
return this.taskArray.shift();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user