codeant-ai-for-open-source[bot] commented on code in PR #40868:
URL: https://github.com/apache/superset/pull/40868#discussion_r3375826724


##########
superset-websocket/src/index.ts:
##########
@@ -513,9 +524,21 @@ export const cleanChannel = (channel: string) => {
 // server startup
 
 if (startServer) {
+  // Last-resort handlers so an unhandled async error is recorded through the
+  // configured logger instead of printing a default trace (or, for an
+  // unhandled rejection, terminating the process on newer Node versions).

Review Comment:
   **Suggestion:** The unhandled-rejection logger interpolates an `unknown` 
value directly into a template string; if the rejection reason is a `Symbol`, 
this throws a new `TypeError` inside the global handler. Normalize the reason 
first (e.g., safe stringification) so the handler never throws while handling 
an error. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ WebSocket sidecar may crash on Symbol rejection.
   - ⚠️ Original rejection reason not logged through logger.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Start the websocket sidecar so the `if (startServer)` block in
   `superset-websocket/src/index.ts` (lines 7–41 of the Read output) executes 
and registers
   the `process.on('unhandledRejection', ...)` handler shown at lines 11–13:
   
      process.on('unhandledRejection', (reason: unknown) => {
   
        logger.error(`Unhandled promise rejection: ${reason}`);
   
      });
   
   2. From a test harness or debug script running in the same Node process, 
trigger the
   global unhandled-rejection listener by calling 
`process.emit('unhandledRejection',
   Symbol('test'), Promise.resolve());`, which uses Node's standard 
`unhandledRejection`
   event path without modifying `superset-websocket/src/index.ts`.
   
   3. The event dispatch invokes the listener defined in 
`superset-websocket/src/index.ts`
   (lines 11–13 from the Read tool), passing the `Symbol('test')` value as the 
`reason`
   argument into the template literal `logger.error(\`Unhandled promise 
rejection:
   ${reason}\`);`.
   
   4. When `reason` is a `Symbol`, the template string forces a 
`ToString(reason)`
   conversion, which throws `TypeError: Cannot convert a Symbol value to a 
string`, causing
   the global `unhandledRejection` handler itself to throw while handling an 
error and
   potentially terminating the websocket sidecar process instead of logging the 
original
   rejection.
   ```
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=4bb8e24a4b3b47468d04d909a22b2900&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=4bb8e24a4b3b47468d04d909a22b2900&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-websocket/src/index.ts
   **Line:** 527:529
   **Comment:**
        *Type Error: The unhandled-rejection logger interpolates an `unknown` 
value directly into a template string; if the rejection reason is a `Symbol`, 
this throws a new `TypeError` inside the global handler. Normalize the reason 
first (e.g., safe stringification) so the handler never throws while handling 
an error.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40868&comment_hash=e8d1f816a7caf57fcb26d093b548a688f5b0322d16bc729994707122a799cd74&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40868&comment_hash=e8d1f816a7caf57fcb26d093b548a688f5b0322d16bc729994707122a799cd74&reaction=dislike'>👎</a>



##########
superset-websocket/src/index.ts:
##########
@@ -513,9 +524,21 @@ export const cleanChannel = (channel: string) => {
 // server startup
 
 if (startServer) {
+  // Last-resort handlers so an unhandled async error is recorded through the
+  // configured logger instead of printing a default trace (or, for an
+  // unhandled rejection, terminating the process on newer Node versions).
+  process.on('unhandledRejection', (reason: unknown) => {
+    logger.error(`Unhandled promise rejection: ${reason}`);
+  });

Review Comment:
   **Suggestion:** The uncaught-exception handler assumes the thrown value is 
always an `Error` and dereferences `stack/message`; JavaScript can throw `null` 
or other non-Error values, which would make this handler throw again while 
processing a fatal error. Guard the value shape before accessing properties to 
avoid a secondary crash in the exception path. [null pointer]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Fatal exceptions with null causes break global logging.
   - ⚠️ Crash safety promises not met on unusual throws.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Start the websocket sidecar so the `if (startServer)` block in
   `superset-websocket/src/index.ts` (lines 7–41 of the Read output) executes 
and registers
   the `process.on('uncaughtException', ...)` handler at lines 14–16:
   
      process.on('uncaughtException', (err: Error) => {
   
        logger.error(`Uncaught exception: ${err.stack ?? err.message}`);
   
      });
   
   2. From a test harness or debug script running in the same Node process, 
simulate a
   non-Error throw by calling `process.emit('uncaughtException', null as 
any);`, which
   invokes the registered `uncaughtException` handler in 
`superset-websocket/src/index.ts`
   without modifying production code.
   
   3. The handler executes the code shown above (lines 14–16 from the Read 
tool), attempting
   to evaluate `err.stack ?? err.message` where `err` is `null`, so the first 
property access
   `err.stack` is effectively `null.stack`.
   
   4. Because `null.stack` throws `TypeError: Cannot read properties of null 
(reading
   'stack')`, the global `uncaughtException` handler itself throws a second 
error while
   handling a fatal exception, preventing the configured logger from recording 
the original
   exception and undermining the crash-safety guarantees described in the 
startup comment.
   ```
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=771f6571ac194d30a9426aa112dbb3a1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=771f6571ac194d30a9426aa112dbb3a1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-websocket/src/index.ts
   **Line:** 530:532
   **Comment:**
        *Null Pointer: The uncaught-exception handler assumes the thrown value 
is always an `Error` and dereferences `stack/message`; JavaScript can throw 
`null` or other non-Error values, which would make this handler throw again 
while processing a fatal error. Guard the value shape before accessing 
properties to avoid a secondary crash in the exception path.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40868&comment_hash=3bfce7aef2188b7ad21b20e7b52889c978d7d1eae08754c352d01782d7db16aa&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40868&comment_hash=3bfce7aef2188b7ad21b20e7b52889c978d7d1eae08754c352d01782d7db16aa&reaction=dislike'>👎</a>



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to