mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 05:43:50 +02:00
[AI-generated] Fix unhandled rejection when disposing invalid input (#413)
* Fix input dispose rejection handling * Move input disposal regression test
This commit is contained in:
+5
-1
@@ -527,8 +527,12 @@ export class Input<S extends Source = Source> extends EventEmitter<InputEvents>
|
|||||||
}
|
}
|
||||||
this._sourceRefs.length = 0;
|
this._sourceRefs.length = 0;
|
||||||
|
|
||||||
|
if (this._demuxerPromise) {
|
||||||
|
// The demuxer promise may already be rejected after failed format detection.
|
||||||
void this._demuxerPromise
|
void this._demuxerPromise
|
||||||
?.then(demuxer => demuxer.dispose());
|
.then(demuxer => demuxer.dispose())
|
||||||
|
.catch(() => {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { expect, test } from 'vitest';
|
||||||
|
import { Input, UnsupportedInputFormatError } from '../../src/input.js';
|
||||||
|
import { ALL_FORMATS } from '../../src/input-format.js';
|
||||||
|
import { BufferSource } from '../../src/source.js';
|
||||||
|
|
||||||
|
test('Disposing after failed format detection does not emit an unhandled rejection', async () => {
|
||||||
|
const input = new Input({
|
||||||
|
source: new BufferSource(new Uint8Array([1, 2, 3, 4])),
|
||||||
|
formats: ALL_FORMATS,
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(input.getFormat()).rejects.toThrow(UnsupportedInputFormatError);
|
||||||
|
|
||||||
|
const unhandledRejections: unknown[] = [];
|
||||||
|
const onUnhandledRejection = (reason: unknown) => {
|
||||||
|
unhandledRejections.push(reason);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.on('unhandledRejection', onUnhandledRejection);
|
||||||
|
try {
|
||||||
|
input.dispose();
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 0));
|
||||||
|
} finally {
|
||||||
|
process.off('unhandledRejection', onUnhandledRejection);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(unhandledRejections).toEqual([]);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user