devowlio / node-lame

LAME is an open-source encoder that encodes and decodes audio to the MP3 file format. For all MP3 needs a Node.js wrapper of the full LAME command line.
Other
82 stars 9 forks source link

Silent Failure #22

Closed petrhdk closed 3 years ago

petrhdk commented 3 years ago

Exceptions during the execution of enc.encode() simply terminate the node process. The developer has no clue what went wrong and the exception/rejection can not be catched.

Am I missing something, is this intended behavior, or can we go on to improving on it? :D


minimal reproducable example:

const Lame = require('node-lame').Lame;

const encoder = new Lame({
    raw: true,
    output: "DOES_NOT_EXIST/output.mp3",
})
    .setBuffer(Buffer.alloc(100, 0x00))
    .encode()
    .then(() => {
        console.log('encoding finished');  // NEVER REACHED
    })
    .catch((err) => {
        console.log('something went wrong');  // NEVER REACHED EITHER
    });
jankarres commented 3 years ago

I am sorry for the very late reply. And thank you for the demo. It helped to debug it.

When does it happen? Only in the edge-case that the file to encode was set via setBuffer() and it is an allocated buffer without any content and at the same time the output file do not exist.

Why does the bug happen? We execute lame via spawn(). lame cannot read this file/buffer and do not know there it should write its output to. Therefore, it closes (not fails) immediately with an exit code 255. This exit code as a closing signal was not yet handled to resolve the promise.

Solution: Handle exist code 255 in process closing like an error.

Fixed and released in version 1.3.1.