jason810496 commented on code in PR #77306:
URL: https://github.com/apache/airflow/pull/77306#discussion_r4694791333


##########
ts-sdk/src/cli/pack.ts:
##########
@@ -115,24 +129,42 @@ function readSdkVersion(): string {
 }
 
 function readBundleManifest(bundlePath: string): BundleManifest {
+  // On macOS Node writes a piped stderr asynchronously, so output past the 64 
KiB pipe buffer is
+  // lost when the bundle exits, and Node prints the whole minified line 
before the error.
+  // Writes to a file are synchronous.
+  const stderrDir = mkdtempSync(path.join(tmpdir(), "airflow-ts-pack-"));
+  const stderrPath = path.join(stderrDir, "stderr");

Review Comment:
   Nothing caps this file now, so a bundle spamming stderr for 60s could fill 
tmpdir. Is that worth guarding?



##########
ts-sdk/src/cli/pack.ts:
##########
@@ -115,24 +129,42 @@ function readSdkVersion(): string {
 }
 
 function readBundleManifest(bundlePath: string): BundleManifest {
+  // On macOS Node writes a piped stderr asynchronously, so output past the 64 
KiB pipe buffer is
+  // lost when the bundle exits, and Node prints the whole minified line 
before the error.
+  // Writes to a file are synchronous.
+  const stderrDir = mkdtempSync(path.join(tmpdir(), "airflow-ts-pack-"));
+  const stderrPath = path.join(stderrDir, "stderr");
+  const stderrFd = openSync(stderrPath, "w");
   let stdout: string;
   try {
     stdout = execFileSync(process.execPath, [bundlePath, 
AIRFLOW_METADATA_FLAG], {
       encoding: "utf-8",
+      stdio: ["pipe", "pipe", stderrFd],
       timeout: MANIFEST_TIMEOUT_MS,
       maxBuffer: MANIFEST_MAX_BUFFER_BYTES,
     });
+    // Still pass on what a working bundle logs, such as warnings from user 
code.
+    const { text, skippedBytes } = readEnd(stderrPath, 
STDERR_READ_LIMIT_BYTES);
+    if (skippedBytes > 0) {
+      process.stderr.write(`[first ${skippedBytes} bytes of the bundle's 
stderr omitted]\n`);
+    }
+    if (text) process.stderr.write(text);
   } catch (error) {
-    const stderr = (error as { stderr?: string }).stderr ?? "";
+    const stderr = readEnd(stderrPath, STDERR_READ_LIMIT_BYTES).text;
     const reported = stderr
       .split("\n")
       .reverse()
       .find((line) => /^\w*Error: /.test(line.trim()))
       ?.trim();
     throw new Error(
-      reported ?? `Running the bundle with ${AIRFLOW_METADATA_FLAG} failed: 
${String(error)}`,
+      reported ??
+        `Running the bundle with ${AIRFLOW_METADATA_FLAG} failed: 
${String(error)}\n` +
+          stderr.trimEnd().slice(-STDERR_TAIL_CHARS),
       { cause: error },
     );

Review Comment:
   If the passthrough fails (say EPIPE), we'd report a good bundle as failed. 
How about catching only the `execFileSync` call?
   
   ```suggestion
     try {
       try {
         stdout = execFileSync(process.execPath, [bundlePath, 
AIRFLOW_METADATA_FLAG], {
           encoding: "utf-8",
           stdio: ["pipe", "pipe", stderrFd],
           timeout: MANIFEST_TIMEOUT_MS,
           maxBuffer: MANIFEST_MAX_BUFFER_BYTES,
         });
       } catch (error) {
         const stderr = readEnd(stderrPath, STDERR_READ_LIMIT_BYTES).text;
         const reported = stderr
           .split("\n")
           .reverse()
           .find((line) => /^\w*Error: /.test(line.trim()))
           ?.trim();
         throw new Error(
           reported ??
             `Running the bundle with ${AIRFLOW_METADATA_FLAG} failed: 
${String(error)}\n` +
               stderr.trimEnd().slice(-STDERR_TAIL_CHARS),
           { cause: error },
         );
       }
       // Still pass on what a working bundle logs, such as warnings from user 
code.
       const { text, skippedBytes } = readEnd(stderrPath, 
STDERR_READ_LIMIT_BYTES);
       if (skippedBytes > 0) {
         process.stderr.write(`[first ${skippedBytes} bytes of the bundle's 
stderr omitted]\n`);
       }
       if (text) process.stderr.write(text);
   ```



##########
ts-sdk/src/cli/pack.ts:
##########
@@ -115,24 +129,42 @@ function readSdkVersion(): string {
 }
 
 function readBundleManifest(bundlePath: string): BundleManifest {
+  // On macOS Node writes a piped stderr asynchronously, so output past the 64 
KiB pipe buffer is
+  // lost when the bundle exits, and Node prints the whole minified line 
before the error.
+  // Writes to a file are synchronous.
+  const stderrDir = mkdtempSync(path.join(tmpdir(), "airflow-ts-pack-"));
+  const stderrPath = path.join(stderrDir, "stderr");
+  const stderrFd = openSync(stderrPath, "w");

Review Comment:
   If `openSync` throws, the temp dir leaks because we are not inside the `try` 
yet. Maybe clean it up here?
   
   ```suggestion
     let stderrFd: number;
     try {
       stderrFd = openSync(stderrPath, "w");
     } catch (error) {
       rmSync(stderrDir, { recursive: true, force: true });
       throw error;
     }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to