Skip to content

Commit 22fe0c9

Browse files
committed
Return empty string if fails to detect file type
1 parent dda8875 commit 22fe0c9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

static/main-preload.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,16 @@
9797
}
9898

9999
async function readFileTypeFromBuffer(buffer) {
100-
const result = await FileType.fromBuffer(buffer)
101-
return result != null ? result.mime : ''
100+
try {
101+
const result = await FileType.fromBuffer(buffer)
102+
if (result == null) {
103+
throw new Error('Failed to detect file type from the buffer')
104+
}
105+
return result.mime
106+
} catch (error) {
107+
console.warn(error)
108+
return ''
109+
}
102110
}
103111

104112
function parseCSON(value) {

0 commit comments

Comments
 (0)