Skip to content

Commit

Permalink
Properly catch error inside MediaInfoModule
Browse files Browse the repository at this point in the history
  • Loading branch information
buzz committed Sep 2, 2021
1 parent 85956e8 commit cae7183
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 3 additions & 1 deletion __tests__/error.wasmLoading.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ describe('Error on WASM loading', () => {
})

it('should return error via Promise', () =>
expect(MediaInfo({ locateFile: () => 'file_does_not_exist.wasm' })).rejects.toThrow())
expect(MediaInfo({ locateFile: () => 'file_does_not_exist.wasm' })).rejects.toThrow(
/no such file/
))
})
22 changes: 14 additions & 8 deletions src/mediainfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,20 @@ function MediaInfoFactory(
}

// Wait for WASM module to be fetched and loaded
MediaInfoModuleFactory(mediaInfoModuleFactoryOpts).then((wasmModule: MediaInfoModule) => {
const format = mergedOptions.format === 'object' ? 'JSON' : mergedOptions.format
const wasmModuleInstance: MediaInfoWasmInterface = new wasmModule.MediaInfo(
format as FormatType,
mergedOptions.coverData as boolean
)
callback(new MediaInfo(wasmModuleInstance, mergedOptions))
})
MediaInfoModuleFactory(mediaInfoModuleFactoryOpts)
.then((wasmModule: MediaInfoModule) => {
const format = mergedOptions.format === 'object' ? 'JSON' : mergedOptions.format
const wasmModuleInstance: MediaInfoWasmInterface = new wasmModule.MediaInfo(
format as FormatType,
mergedOptions.coverData as boolean
)
callback(new MediaInfo(wasmModuleInstance, mergedOptions))
})
.catch((err) => {
if (errCallback) {
errCallback(err)
}
})
}

export type {
Expand Down

0 comments on commit cae7183

Please sign in to comment.