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

View File

@ -139,6 +139,18 @@ describe('TaskRunner', () => {
}).toThrowError(/Test error 1, Test error 2/); }).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', () => { it('verifies that at least one model asset option is provided', () => {
expect(() => { expect(() => {
taskRunner.setOptions({}); taskRunner.setOptions({});