Allow task to recover after a failed graph start

PiperOrigin-RevId: 500324587
This commit is contained in:
Sebastian Schmidt 2023-01-06 21:04:57 -08:00 committed by Copybara-Service
parent b4ede6db7b
commit ed0054836a
2 changed files with 24 additions and 9 deletions

View File

@ -164,16 +164,19 @@ export abstract class TaskRunner {
/** Throws the error from the error listener if an error was raised. */
private handleErrors() {
const errorCount = this.processingErrors.length;
if (errorCount === 1) {
// Re-throw error to get a more meaningful stacktrace
throw new Error(this.processingErrors[0].message);
} else if (errorCount > 1) {
throw new Error(
'Encountered multiple errors: ' +
this.processingErrors.map(e => e.message).join(', '));
try {
const errorCount = this.processingErrors.length;
if (errorCount === 1) {
// Re-throw error to get a more meaningful stacktrace
throw new Error(this.processingErrors[0].message);
} else if (errorCount > 1) {
throw new Error(
'Encountered multiple errors: ' +
this.processingErrors.map(e => e.message).join(', '));
}
} finally {
this.processingErrors = [];
}
this.processingErrors = [];
}
/** Configures the `externalFile` option */

View File

@ -139,6 +139,18 @@ describe('TaskRunner', () => {
}).toThrowError(/Test error 1, Test error 2/);
});
it('clears errors once thrown', () => {
taskRunner.enqueueError('Test error');
expect(() => {
taskRunner.setGraph(new Uint8Array(0), /* isBinary= */ true);
}).toThrowError(/Test error/);
expect(() => {
taskRunner.setGraph(new Uint8Array(0), /* isBinary= */ true);
}).not.toThrow();
});
it('verifies that at least one model asset option is provided', () => {
expect(() => {
taskRunner.setOptions({});