Skip to content

Conversation

@shaheerkhan00
Copy link

@shaheerkhan00 shaheerkhan00 commented Jan 23, 2026

What does this PR do?

In Node 22, the CLI crashes with TypeError: Cannot convert undefined or null to object when a function execution log contains null for metadata fields like scheduledAt. This occurs because typeof null returns 'object', leading the parser to attempt table rendering on non-iterable values.

The Solution

  • Added a guard clause at the start of drawTable to handle null or empty data arrays.
  • Implemented null-safe spreading (item || {}) within reduce and map to prevent illegal object conversions.
  • Updated the row value loop to explicitly handle null placeholders with a hyphen (-).

Test Plan

Test Plan
I verified these changes by creating a reproduction script that simulates the exact conditions under which the TypeError occurs in Node 22 (specifically when a function execution log contains null metadata from a database-triggered event).

Verification Steps:

Environment: Node v22.15.0.

Reproduction Script: Created a script that passes a mock execution object with scheduledAt: null into the drawTable function.

Command Execution: Ran the test using npx tsx repro_bug_sk.js.

Test Results:

Test 1 (Null Metadata): Passed. The table rendered correctly, displaying a hyphen - for the null scheduledAt field instead of crashing with a TypeError.

Test 2 (Null Array Element): Passed. The parser gracefully handled an array containing a null element [null] without attempting to access keys.
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)
Output:
--- Test 1: Simulating Database Trigger with Null values ---

$id │ status │ duration │ scheduledAt │ trigger
───────────┼───────────┼──────────┼─────────────┼──────────
65ae12345 │ completed │ 0.123 │ - │ database

✅ Test 1 Passed: Table rendered successfully despite null values.

--- Test 2: Simulating Empty Object array ---
[]
✅ Test 2 Passed: Handled [null] array gracefully.

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

(Write your answer here.)

Summary by CodeRabbit

  • Bug Fixes
    • Improved robustness when processing data with null or undefined values in tables
    • Fixed edge cases that could cause crashes when handling missing fields or empty datasets
    • Enhanced empty state handling for safer data processing

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Walkthrough

The diff introduces null-safety guards throughout the parser module to handle edge cases with null or undefined values. Changes include adding null checks in object-type field detection, implementing early returns for empty or falsy data in drawTable, using safe object spreading patterns (item || {}) to prevent errors when elements are null, and adding safeguards for row value extraction. A new reproduction script is added to test drawTable with edge cases including null values and null array elements, using try-catch blocks to verify robustness.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing null value handling in drawTable to prevent a Node 22 crash, which aligns with the core objective and changes made.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@repro_bug_sk.js`:
- Around line 1-3: The file repro_bug_sk.js is a manual reproduction script and
should be removed from the repository; delete repro_bug_sk.js (or move it out to
local notes/docs) and remove any references to it, and if you must keep a local
copy update its import of './lib/parser.ts' (referenced via drawTable import) to
a runtime-compatible module (e.g., './lib/parser.js') or remove the import
entirely so the repo does not require tsx/ts-node to run; ensure
package.json/test remains unchanged if you remove the script.
🧹 Nitpick comments (2)
lib/parser.ts (1)

58-62: Guard clause correctly handles empty and null-first-element cases.

The early return prevents crashes when data is falsy, empty, or when the first element is null. However, consider whether printing "[]" is the right output when data[0] === null but other elements might be valid objects.

If an array like [null, {id: 1}] is passed, the current code exits early with "[]" instead of rendering the valid second element. If this edge case matters, you could filter out null elements before checking:

♻️ Optional: Handle arrays with leading nulls
-  if (!data || data.length === 0 || data[0] === null) {
+  // Filter out null elements first
+  const filteredData = data?.filter(item => item !== null) ?? [];
+  if (filteredData.length === 0) {
     console.log("[]");
     return;
   }
+  data = filteredData;
repro_bug_sk.js (1)

17-24: Test 1 coverage looks good but lacks assertion rigor.

The test correctly exercises the null field scenario (scheduledAt: null). However, using console.log for pass/fail output makes it difficult to integrate with CI pipelines. The success message appears even if drawTable silently fails without throwing.

If keeping this as a manual script, consider verifying the output or at minimum ensuring no error was thrown:

// The current test passes even if drawTable outputs incorrect data
// Consider adding output capture/verification if this becomes a real test

Comment on lines +1 to +3
// repro_bug.js

import { drawTable } from './lib/parser.ts'; // Change .js to .ts
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's find and examine the repro_bug_sk.js file
fd -name "repro_bug_sk.js" -type f

Repository: appwrite/sdk-for-cli

Length of output: 294


🏁 Script executed:

# Check repository structure
git ls-files | grep -E "(repro_bug|test|spec)" | head -20

Repository: appwrite/sdk-for-cli

Length of output: 212


🏁 Script executed:

# Check package.json for test configuration
cat package.json 2>/dev/null | head -50

Repository: appwrite/sdk-for-cli

Length of output: 2283


🏁 Script executed:

# Look for test directories
fd -type d -name "__tests__" -o -name "test" -o -name "tests" -o -name "spec"

Repository: appwrite/sdk-for-cli

Length of output: 234


🏁 Script executed:

# Read the actual repro_bug_sk.js file
cat -n repro_bug_sk.js

Repository: appwrite/sdk-for-cli

Length of output: 1220


🏁 Script executed:

# Check if this file is in .gitignore
cat .gitignore 2>/dev/null | grep -i "repro"

Repository: appwrite/sdk-for-cli

Length of output: 46


🏁 Script executed:

# Check if lib/parser.ts exists
fd -name "parser.ts" -type f

Repository: appwrite/sdk-for-cli

Length of output: 294


🏁 Script executed:

# Check project root structure
ls -la | grep -E "^-.*\.(js|ts)$"

Repository: appwrite/sdk-for-cli

Length of output: 306


Remove this reproduction script from the repository.

The filename in line 1's comment (repro_bug.js) doesn't match the actual filename (repro_bug_sk.js). More importantly, this is a manual debug script rather than a proper automated test. Since the project has no test framework configured ("test": "echo \"Error: no test specified\" && exit 1"), either remove this file or move it to local documentation/notes outside the repository.

The direct .ts import also requires tsx or ts-node to execute, which adds unnecessary complexity for what should be manual verification if needed.

🤖 Prompt for AI Agents
In `@repro_bug_sk.js` around lines 1 - 3, The file repro_bug_sk.js is a manual
reproduction script and should be removed from the repository; delete
repro_bug_sk.js (or move it out to local notes/docs) and remove any references
to it, and if you must keep a local copy update its import of './lib/parser.ts'
(referenced via drawTable import) to a runtime-compatible module (e.g.,
'./lib/parser.js') or remove the import entirely so the repo does not require
tsx/ts-node to run; ensure package.json/test remains unchanged if you remove the
script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant