-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(node): prevent stdout double-write when streamOutput=true in executeJar() #399
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,8 +42,10 @@ function executeJar(args: string[], executionOptions: JarExecutionOptions = {}): | |
| const chunk = data.toString(); | ||
| if (streamOutput) { | ||
| process.stdout.write(chunk); | ||
| } else { | ||
| // Only accumulate when not streaming to avoid double-write by the caller | ||
| stdout += chunk; | ||
| } | ||
| stdout += chunk; | ||
| }); | ||
|
|
||
| javaProcess.stderr.on('data', (data) => { | ||
|
|
@@ -56,7 +58,9 @@ function executeJar(args: string[], executionOptions: JarExecutionOptions = {}): | |
|
|
||
| javaProcess.on('close', (code) => { | ||
| if (code === 0) { | ||
| resolve(stdout); | ||
| // When streamOutput=true, content was already written to process.stdout in real-time. | ||
| // Return empty string to prevent callers from double-writing the same output. | ||
| resolve(streamOutput ? '' : stdout); | ||
|
Comment on lines
+67
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This changes
Also applies to: 110-112 🤖 Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch — you are right that tying
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Approach: always accumulate + always return real In javaProcess.stdout.on('data', (data) => {
const chunk = data.toString();
stdout += chunk; // always accumulate for callers
if (streamOutput) {
process.stdout.write(chunk); // stream in real-time for CLI
}
});
javaProcess.on('close', (code) => {
if (code === 0) {
resolve(stdout); // always return real content — callers see the full string
} else {
const errorOutput = stderr || stdout;
reject(new Error(`The opendataloader-pdf CLI exited with code ${code}.\n\n${errorOutput}`));
}
});Then in // cli.ts (rough sketch)
const result = await convert(inputPaths, options);
if (options.quiet) {
// streaming was off, nothing was written yet — print now
process.stdout.write(result);
}
// else: output was already streamed in real-time; skip re-printingThis keeps the 🧠 Learnings used |
||
| } else { | ||
| const errorOutput = stderr || stdout; | ||
| const error = new Error( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.