Skip to content

fix(node): stdout output is written twice when quiet option is not set — streamOutput in executeJar conflicts with CLI output layer #398

@kuishou68

Description

@kuishou68

Bug Description

In node/opendataloader-pdf/src/index.ts, when convert() is called from the CLI without the quiet flag, output is written to process.stdout twice.

Root Cause

executeJar() is called with streamOutput: !options.quiet. When streamOutput=true, every data chunk from the Java process is immediately written to process.stdout:

javaProcess.stdout.on('data', (data) => {
  const chunk = data.toString();
  if (streamOutput) {
    process.stdout.write(chunk);  // <-- writes to stdout in real-time
  }
  stdout += chunk;  // <-- also accumulated
});

Then the resolved stdout string is returned back to cli.ts, which writes it again:

// cli.ts
const output = await convert(inputPaths, convertOptions);
if (output && !convertOptions.quiet) {
  process.stdout.write(output);  // <-- second write of the same content!
}

Fix

When streamOutput=true, the accumulated stdout variable should be returned as an empty string (since it was already written to `process.stdout' in real-time), preventing the CLI from double-printing.

javaProcess.on('close', (code) => {
  if (code === 0) {
    // If already streamed, return empty to avoid double-write by caller
    resolve(streamOutput ? '' : stdout);
  } else {
    ...
  }
});

Impact

All CLI users who do not pass --quiet see every line of output duplicated. This is a significant UX regression.

Affected File

node/opendataloader-pdf/src/index.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions