Skip to content

Commit e0f0e46

Browse files
committed
Enhance error message
1 parent 86d73dc commit e0f0e46

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

src/createWorker.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,21 @@ module.exports = (_options = {}) => {
176176
});
177177
} else if (status === 'reject') {
178178
rejects[action](payload);
179-
throw Error(payload);
179+
throw Error(
180+
`${payload}
181+
182+
To get more informaion for debugging, please add logger in createWorker():
183+
184+
const worker = createWorker({
185+
logger: ({ message }) => console.log(message),
186+
});
187+
188+
Even more details:
189+
190+
const { setLogging } = require('@ffmpeg/ffmpeg');
191+
setLogging(true);
192+
`,
193+
);
180194
} else if (status === 'progress') {
181195
parseProgress(payload, progress);
182196
logger(payload);

src/worker-script/index.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ const defaultArgs = require('./constants/defaultArgs');
33
const strList2ptr = require('./utils/strList2ptr');
44
const getTransferables = require('../utils/getTransferables');
55

6+
const NO_LOAD_ERROR = 'FFmpegCore is not ready, make sure you have completed Worker.load().';
7+
68
let action = 'unknown';
79
let Module = null;
810
let adapter = null;
911
let ffmpeg = null;
1012

1113
const load = ({ workerId, payload: { options: { corePath } } }, res) => {
12-
if (Module == null) {
14+
if (Module === null) {
1315
const Core = adapter.getCore(corePath);
1416
Core()
1517
.then(async (_Module) => {
@@ -33,22 +35,30 @@ const FS = ({
3335
args,
3436
},
3537
}, res) => {
36-
res.resolve({
37-
message: `Complete ${method}`,
38-
data: Module.FS[method](...args),
39-
});
38+
if (Module === null) {
39+
throw NO_LOAD_ERROR;
40+
} else {
41+
res.resolve({
42+
message: `Complete ${method}`,
43+
data: Module.FS[method](...args),
44+
});
45+
}
4046
};
4147

4248
const run = ({
4349
payload: {
4450
args: _args,
4551
},
4652
}, res) => {
47-
const args = [...defaultArgs, ..._args.trim().split(' ')].filter((s) => s.length !== 0);
48-
ffmpeg(args.length, strList2ptr(Module, args));
49-
res.resolve({
50-
message: `Complete ${args.join(' ')}`,
51-
});
53+
if (Module === null) {
54+
throw NO_LOAD_ERROR;
55+
} else {
56+
const args = [...defaultArgs, ..._args.trim().split(' ')].filter((s) => s.length !== 0);
57+
ffmpeg(args.length, strList2ptr(Module, args));
58+
res.resolve({
59+
message: `Complete ${args.join(' ')}`,
60+
});
61+
}
5262
};
5363

5464
exports.dispatchHandlers = (packet, send) => {

0 commit comments

Comments
 (0)