-
Notifications
You must be signed in to change notification settings - Fork 1.7k
JS: new Quality
query - Unhandled errors in .pipe()
chain
#19544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…error handlers in `Node.js` streams
Add tests for chained stream methods and non-stream pipe objects
…ld be flagged by the query
26f0aeb
to
21aa9d1
Compare
…fter pipe operations
…om `pipe()` calls based on accessed properties
…pipe method detection
…ied as `pipe` calls on streams
…and `javascript-code-quality.qls`
21aa9d1
to
b104871
Compare
…t flag such instances.
…n and some popular library ones
…n one passes function as second arg to `pipe`
1fba9e0
to
b10a948
Compare
… from being flagged by unhandled pipe error query
QHelp previews: javascript/ql/src/Quality/UnhandledStreamPipe.qhelpNode.js stream pipe without error handlingIn Node.js, calling the RecommendationInstead of using If you must use ExampleThe following code snippet demonstrates a problematic usage of the const fs = require('fs');
const source = fs.createReadStream('source.txt');
const destination = fs.createWriteStream('destination.txt');
// Bad: No error handling
source.pipe(destination); A better approach is to use the const { pipeline } = require('stream');
const fs = require('fs');
const source = fs.createReadStream('source.txt');
const destination = fs.createWriteStream('destination.txt');
// Good: Using pipeline for automatic error handling
pipeline(
source,
destination,
(err) => {
if (err) {
console.error('Pipeline failed:', err);
} else {
console.log('Pipeline succeeded');
}
}
); Alternatively, if you need to use const fs = require('fs');
const source = fs.createReadStream('source.txt');
const destination = fs.createWriteStream('destination.txt');
// Alternative Good: Manual error handling with pipe()
source.on('error', (err) => {
console.error('Source stream error:', err);
destination.destroy(err);
});
destination.on('error', (err) => {
console.error('Destination stream error:', err);
source.destroy(err);
});
source.pipe(destination); References
|
No description provided.