Skip to content

Commit 4608363

Browse files
authored
Use AggregateError for errors while disposing (microsoft#159477)
1 parent 9e52480 commit 4608363

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

src/vs/base/common/lifecycle.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,6 @@ export function markAsSingleton<T extends IDisposable>(singleton: T): T {
108108
return singleton;
109109
}
110110

111-
export class MultiDisposeError extends Error {
112-
constructor(
113-
public readonly errors: any[]
114-
) {
115-
super(`Encountered errors while disposing of store. Errors: [${errors.join(', ')}]`);
116-
}
117-
}
118-
119111
export interface IDisposable {
120112
dispose(): void;
121113
}
@@ -146,7 +138,7 @@ export function dispose<T extends IDisposable>(arg: T | IterableIterator<T> | un
146138
if (errors.length === 1) {
147139
throw errors[0];
148140
} else if (errors.length > 1) {
149-
throw new MultiDisposeError(errors);
141+
throw new AggregateError(errors, 'Encountered errors while disposing of store');
150142
}
151143

152144
return Array.isArray(arg) ? [] : arg;

src/vs/base/test/common/lifecycle.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as assert from 'assert';
77
import { Emitter } from 'vs/base/common/event';
8-
import { DisposableStore, dispose, IDisposable, markAsSingleton, MultiDisposeError, ReferenceCollection, SafeDisposable, toDisposable } from 'vs/base/common/lifecycle';
8+
import { DisposableStore, dispose, IDisposable, markAsSingleton, ReferenceCollection, SafeDisposable, toDisposable } from 'vs/base/common/lifecycle';
99
import { ensureNoDisposablesAreLeakedInTestSuite, throwIfDisposablesAreLeaked } from 'vs/base/test/common/utils';
1010

1111
class Disposable implements IDisposable {
@@ -88,10 +88,10 @@ suite('Lifecycle', () => {
8888

8989
assert.ok(disposedValues.has(1));
9090
assert.ok(disposedValues.has(4));
91-
assert.ok(thrownError instanceof MultiDisposeError);
92-
assert.strictEqual((thrownError as MultiDisposeError).errors.length, 2);
93-
assert.strictEqual((thrownError as MultiDisposeError).errors[0].message, 'I am error 1');
94-
assert.strictEqual((thrownError as MultiDisposeError).errors[1].message, 'I am error 2');
91+
assert.ok(thrownError instanceof AggregateError);
92+
assert.strictEqual((thrownError as AggregateError).errors.length, 2);
93+
assert.strictEqual((thrownError as AggregateError).errors[0].message, 'I am error 1');
94+
assert.strictEqual((thrownError as AggregateError).errors[1].message, 'I am error 2');
9595
});
9696

9797
test('Action bar has broken accessibility #100273', function () {
@@ -167,10 +167,10 @@ suite('DisposableStore', () => {
167167

168168
assert.ok(disposedValues.has(1));
169169
assert.ok(disposedValues.has(4));
170-
assert.ok(thrownError instanceof MultiDisposeError);
171-
assert.strictEqual((thrownError as MultiDisposeError).errors.length, 2);
172-
assert.strictEqual((thrownError as MultiDisposeError).errors[0].message, 'I am error 1');
173-
assert.strictEqual((thrownError as MultiDisposeError).errors[1].message, 'I am error 2');
170+
assert.ok(thrownError instanceof AggregateError);
171+
assert.strictEqual((thrownError as AggregateError).errors.length, 2);
172+
assert.strictEqual((thrownError as AggregateError).errors[0].message, 'I am error 1');
173+
assert.strictEqual((thrownError as AggregateError).errors[1].message, 'I am error 2');
174174
});
175175
});
176176

0 commit comments

Comments
 (0)