mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
Added qhelp for UnhandledStreamPipe query
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
const fs = require('fs');
|
||||
const source = fs.createReadStream('source.txt');
|
||||
const destination = fs.createWriteStream('destination.txt');
|
||||
|
||||
// Bad: No error handling
|
||||
source.pipe(destination);
|
||||
@@ -0,0 +1,17 @@
|
||||
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');
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,16 @@
|
||||
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);
|
||||
Reference in New Issue
Block a user