{"record":{"id":"71bf1fe5aca58de3","repo":"t8y2/dbx","slug":"invalid-name-error-message","errorCode":null,"errorMessage":"Invalid ${name}: ${error.message}","messagePattern":"Invalid (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/dbx-core/assets/pi-mcp-bridge.mjs","lineNumber":17,"sourceCode":"import { spawn } from \"node:child_process\";\nimport { writeFile } from \"node:fs/promises\";\nimport { createInterface } from \"node:readline\";\n\nconst MCP_PROGRAM_ENV = \"DBX_PI_MCP_PROGRAM\";\nconst MCP_ARGS_ENV = \"DBX_PI_MCP_ARGS\";\nconst ENABLED_TOOLS_ENV = \"DBX_PI_ENABLED_TOOLS\";\nconst READY_FILE_ENV = \"DBX_PI_BRIDGE_READY_FILE\";\nconst REQUEST_TIMEOUT_MS = 30_000;\n\nfunction parseJsonEnv(name, fallback) {\n  const value = process.env[name];\n  if (!value) return fallback;\n  try {\n    return JSON.parse(value);\n  } catch (error) {\n    throw new Error(`Invalid ${name}: ${error.message}`);\n  }\n}\n\nfunction textFromContent(content) {\n  return (content ?? [])\n    .filter((item) => item?.type === \"text\" && typeof item.text === \"string\")\n    .map((item) => item.text)\n    .join(\"\\n\");\n}\n\nfunction piContent(content) {\n  const result = [];\n  for (const item of content ?? []) {\n    if (item?.type === \"text\" && typeof item.text === \"string\") {\n      result.push({ type: \"text\", text: item.text });\n    } else if (\n      item?.type === \"image\" &&\n      typeof item.data === \"string\" &&","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/crates/dbx-core/assets/pi-mcp-bridge.mjs#L1-L35","documentation":"parseJsonEnv reads an environment variable expected to contain JSON and throws Error('Invalid <name>: <error.message>') when JSON.parse fails. The bridge uses it for MCP_ARGS_ENV and ENABLED_TOOLS_ENV, so malformed JSON in those variables aborts startup.","triggerScenarios":"DBX_PI_MCP_ARGS or DBX_PI_MCP_ENABLED_TOOLS (the configured env names) contain non-JSON text, single quotes instead of double quotes, trailing commas, or are truncated by a size limit.","commonSituations":"Hand-editing env vars in shell (shell quoting strips double quotes); container orchestration templates interpolating incorrectly; log-serialization truncating long values.","solutions":["Set the env var to valid JSON, e.g. DBX_PI_MCP_ARGS='[\"-m\",\"server\"]' with double quotes inside","Validate with `echo \"$VAR\" | python3 -m json.tool` or JSON.parse in node before launch","Prefer a config file/generated env over hand-written shell escaping; check how your shell/systemd/compose passes quotes"],"exampleFix":"// before\nexport DBX_PI_MCP_ARGS=[\"-m\",\"pi_server\"]   # shell strips quotes -> invalid JSON\n// after\nexport DBX_PI_MCP_ARGS='[\"-m\",\"pi_server\"]'","handlingStrategy":"validation","validationCode":"function assertJsonEnv(name) {\n  const v = process.env[name];\n  if (v) JSON.parse(v); // throws early with clear context\n}\nassertJsonEnv('DBX_PI_MCP_ARGS');\nassertJsonEnv('DBX_PI_MCP_ENABLED_TOOLS');","typeGuard":"function isJsonObjectString(v) {\n  try { const p = JSON.parse(v); return p !== null && typeof p === 'object'; }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  const args = parseJsonEnv('DBX_PI_MCP_ARGS', []);\n} catch (e) {\n  console.error('Env DBX_PI_MCP_ARGS is not valid JSON:', e.message);\n  process.exit(1);\n}","preventionTips":["Single-quote JSON values in shell so double quotes survive","Validate env JSON before launching the bridge","Avoid hand-editing: generate env from a config file"],"tags":["json","env-var","configuration"],"backgroundTag":"invalid-json-env-var","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}