Fix out of memory in hash computation by edoardopirovano · Pull Request #550 · github/codeql-action (original) (raw)

Be careful about mixing async-await and callback patterns. Error handling gets tricky because thrown errors don't necessarily correlate to promise rejections.

In this case, this could be rewritten entirely in async-await like so:

const readStream = fs.createReadStream(filepath, "utf8");

for await (const chunk of readStream) { // Handle the chunk }

processCharacter(65535);

Any potential errors would be caught as normal because synchronous functions would throw and asynchronous functions would be rejected (because of the await).