{"record":{"id":"a917afadd3068bc0","repo":"nexu-io/open-design","slug":"authorized-pull-response-is-not-valid-json","errorCode":null,"errorMessage":"authorized pull response is not valid JSON","messagePattern":"authorized pull response is not valid JSON","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/collab/authorized-team-project-pull.ts","lineNumber":107,"sourceCode":"}\n\nfunction requiredString(\n  record: Record<string, unknown>,\n  key: string,\n): string {\n  const value = record[key];\n  if (typeof value !== 'string' || !value.trim()) {\n    throw new Error(`authorized pull receipt has invalid ${key}`);\n  }\n  return value;\n}\n\nfunction parseReceipt(stdout: string): AuthorizedTeamProjectPullReceipt {\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(stdout.trim());\n  } catch {\n    throw new Error('authorized pull response is not valid JSON');\n  }\n  if (!isRecord(parsed)) {\n    throw new Error('authorized pull response must be an object');\n  }\n  const version = parsed.version;\n  if (!Number.isSafeInteger(version) || Number(version) < 0) {\n    throw new Error('authorized pull receipt has invalid version');\n  }\n  return {\n    schemaVersion: parsed.schemaVersion as 1,\n    workspaceId: requiredString(parsed, 'workspaceId'),\n    resourceTeamId: requiredString(parsed, 'resourceTeamId'),\n    viewerMemberId: requiredString(parsed, 'viewerMemberId'),\n    ownerMemberId: requiredString(parsed, 'ownerMemberId'),\n    projectId: requiredString(parsed, 'projectId'),\n    resourceId: requiredString(parsed, 'resourceId'),\n    ref: parsed.ref as 'published',\n    version: Number(version),","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/collab/authorized-team-project-pull.ts#L89-L125","documentation":"Thrown by parseReceipt when JSON.parse fails on the trimmed stdout from the Vela `team-projects pull` command. The authorizer is expected to print a JSON receipt; anything that is not valid JSON (an error message, a banner, a partial line, or an empty string) trips this before any field validation runs.","triggerScenarios":"Vela CLI printed a human-readable error to stdout instead of JSON (auth failure, network error, unknown subcommand), the process was killed mid-output, or stdout mixing warnings with the JSON body.","commonSituations":"Vela CLI version that lacks the `team-projects pull --json` subcommand (it prints 'unknown command'), an expired/missing login so Vela emits an auth error, or a proxy/wrapper that prefixes stdout with a log line.","solutions":["Run the same Vela command manually and read what it actually prints to stdout.","Confirm the Vela CLI is logged in and supports `team-projects pull --json`.","Upgrade the Vela CLI to a version compatible with this daemon build.","Use isAuthorizedTeamProjectPullUnavailable(error) to detect the 'unknown command' case and fail open if appropriate."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"function looksLikeJsonReceipt(stdout: string): boolean {\n  const trimmed = stdout.trim();\n  if (!trimmed) return false;\n  try { JSON.parse(trimmed); return true; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  parseReceipt(stdout);\n} catch (err) {\n  if (isAuthorizedTeamProjectPullUnavailable(err)) {\n    // CLI lacks the subcommand — fail open per the documented policy\n  } else if (err instanceof Error && /not valid JSON/.test(err.message)) {\n    // log stdout, surface a 'vela output malformed' error, abort the pull\n  }\n  throw err;\n}","preventionTips":["Confirm the Vela CLI is logged in and supports `team-projects pull --json` before relying on it.","Capture and log raw Vela stdout/stderr so non-JSON output is diagnosable.","Use isAuthorizedTeamProjectPullUnavailable to distinguish 'unsupported CLI' from 'malformed output'."],"tags":["collab","vela","receipt","json","team-projects"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}