srt-vtt-parser
srt-vtt-parser copied to clipboard
Edge case in parser
Unintentionally, I fed an mp4 file to this library (yes, I know, not really the ideal usage. But bear with me for a moment).
The parser function failed with:
TypeError: Cannot read properties of undefined (reading 'replace')
at timestampToMillisecond (/private/var/tmp/_bazel_danielepolencic/198d81e4f6aafdc263b492f2c04a5df7/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/packages/main/main.sh.runfiles/_main/node_modules/.aspect_rules_js/@[email protected]/node_modules/@plussub/srt-vtt-parser/dist/src/srtParser.js:18:29)
at Object.TIME_LINE (/private/var/tmp/_bazel_danielepolencic/198d81e4f6aafdc263b492f2c04a5df7/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/packages/main/main.sh.runfiles/_main/node_modules/.aspect_rules_js/@[email protected]/node_modules/@plussub/srt-vtt-parser/dist/src/srtParser.js:60:24)
at Object.start (/private/var/tmp/_bazel_danielepolencic/198d81e4f6aafdc263b492f2c04a5df7/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/packages/main/main.sh.runfiles/_main/node_modules/.aspect_rules_js/@[email protected]/node_modules/@plussub/srt-vtt-parser/dist/src/srtParser.js:30:51)
at Object.srtParser (/private/var/tmp/_bazel_danielepolencic/198d81e4f6aafdc263b492f2c04a5df7/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/packages/main/main.sh.runfiles/_main/node_modules/.aspect_rules_js/@[email protected]/node_modules/@plussub/srt-vtt-parser/dist/src/srtParser.js:99:31)
at parse (/private/var/tmp/_bazel_danielepolencic/198d81e4f6aafdc263b492f2c04a5df7/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/packages/main/main.sh.runfiles/_main/node_modules/.aspect_rules_js/@[email protected]/node_modules/@plussub/srt-vtt-parser/dist/src/index.js:7:80
So I started digging and found that this line could be undefined.
While I recognised my error and fixed it, I wondered if there was something I could do to prevent this library from crashing again at that particular point (my current thinking is that a broken VTT file might cause the issue). I think the library should either:
- Return an error if the file is invalid
- throw an error
- or return partial results.
How to reproduce the issue:
try {
const caption = await axios.get('https://f005.backblazeb2.com/file/kubefm/interview-miguel-luna-1/social-1.mp4')
console.log('VTT', parseVTT(caption.data as string))
} catch (error) {
console.log('Err', error)
}