Debug: File parts test script for withTracing error reproduction#29
Debug: File parts test script for withTracing error reproduction#29andrewm4894 wants to merge 2 commits intomainfrom
Conversation
Test script to help reproduce "Cannot convert undefined or null to object" error reported with withTracing and file parts in Vercel AI SDK v6. Tests various file part configurations: - base64 string data - data URL string - Uint8Array - Buffer - ArrayBuffer - null/undefined data (edge cases) - Streaming variants Run with: npx ts-node --esm scripts/test-file-parts.ts --gemini 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
|
||
| // Enable debug mode to see PostHog events | ||
| posthog.debug(true); | ||
| console.log(`\n📊 PostHog Config: host=${process.env.POSTHOG_HOST}, key=${process.env.POSTHOG_API_KEY?.substring(0, 10)}...`); |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix this, we should stop logging the actual value (even partially) of POSTHOG_API_KEY and instead log only non-sensitive configuration aspects or boolean-style information (e.g., whether the key is set). This preserves the existing functionality of debugging PostHog configuration without exposing secrets.
The best, minimal-change fix is to modify line 38 to remove ${process.env.POSTHOG_API_KEY?.substring(0, 10)}... and replace it with something that does not reveal the key contents, such as a boolean or masked placeholder. For example: key=${process.env.POSTHOG_API_KEY ? '[set]' : '[missing]'}. This requires no new imports or additional helper functions and keeps the console output informative.
Concretely, in node/scripts/test-file-parts.ts, replace the console.log call on line 38 with one that does not interpolate the key value, only whether it exists. No other lines or files need to change.
| @@ -35,7 +35,7 @@ | ||
|
|
||
| // Enable debug mode to see PostHog events | ||
| posthog.debug(true); | ||
| console.log(`\n📊 PostHog Config: host=${process.env.POSTHOG_HOST}, key=${process.env.POSTHOG_API_KEY?.substring(0, 10)}...`); | ||
| console.log(`\n📊 PostHog Config: host=${process.env.POSTHOG_HOST}, key=${process.env.POSTHOG_API_KEY ? '[set]' : '[missing]'}`); | ||
|
|
||
| const openaiClient = createOpenAI({ | ||
| apiKey: process.env.OPENAI_API_KEY! |
Test script to reproduce "Cannot convert undefined or null to object" error with ToolLoopAgent and file attachments. Tests both generate() and stream() methods with file parts using the Gemini provider. Related: PostHog/posthog-js#2877 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
| ); | ||
|
|
||
| posthog.debug(true); | ||
| console.log(`\n📊 PostHog Config: host=${process.env.POSTHOG_HOST}, key=${process.env.POSTHOG_API_KEY?.substring(0, 10)}...`); |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
In general, the fix is to avoid logging secrets such as API keys entirely, or to log only non-sensitive metadata (e.g., whether a key is present, obfuscated length, or host information). Any diagnostic logging should be careful not to include raw or partially raw secrets.
For this specific case, the best fix without changing functionality is to stop including process.env.POSTHOG_API_KEY in the log line. The rest of the script only needs to know that PostHog is configured; it doesn’t require the key value to be printed. We can keep logging the PostHog host and optionally a boolean flag indicating whether a key is present (which is not sensitive). Concretely, in node/scripts/test-agent-file-parts.ts, replace line 37 so that it either removes the key altogether or replaces it with a non-sensitive indicator like key_present=${Boolean(process.env.POSTHOG_API_KEY)}.
No new helper methods or complex logic are needed; just update the log statement. No new imports are required.
| @@ -34,7 +34,7 @@ | ||
| ); | ||
|
|
||
| posthog.debug(true); | ||
| console.log(`\n📊 PostHog Config: host=${process.env.POSTHOG_HOST}, key=${process.env.POSTHOG_API_KEY?.substring(0, 10)}...`); | ||
| console.log(`\n📊 PostHog Config: host=${process.env.POSTHOG_HOST}, key_present=${Boolean(process.env.POSTHOG_API_KEY)}`); | ||
|
|
||
| const googleClient = createGoogleGenerativeAI({ | ||
| apiKey: process.env.GEMINI_API_KEY! |
Test Scripts for File Parts Error Reproduction
Test scripts to help reproduce and debug the "Cannot convert undefined or null to object" error reported when using
withTracingwith file parts in Vercel AI SDK v6.Scripts
scripts/test-file-parts.tsTests various file part configurations with
generateText:scripts/test-agent-file-parts.tsTests
ToolLoopAgentwith file parts:agent.generate()with file attachmentsagent.stream()with file attachmentsResults
Tests pass with current SDK versions (PostHog AI v6.6.0, Vercel AI SDK v6), suggesting the issue is environment-specific.
Related