{"record":{"id":"10e44d58fb7aa67a","repo":"Budibase/budibase","slug":"project-package-contains-an-invalid-doc-in-base","errorCode":null,"errorMessage":"Project package contains an invalid doc in '${basename(filePath)}'.","messagePattern":"Project package contains an invalid doc in '(.+?)'\\.","errorType":"validation","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/projects/backups/imports.ts","lineNumber":1016,"sourceCode":"      .catch(() => [])\n\n    if (docFiles.length > MAX_PACKAGE_DOCS) {\n      throw new HTTPError(\"Project package contains too many docs.\", 400)\n    }\n    if (docFiles.some(filePath => !filePath.endsWith(\".json\"))) {\n      throw new HTTPError(\n        \"Project package contains unsupported doc files.\",\n        400\n      )\n    }\n\n    const docs = await Promise.all(\n      docFiles\n        .filter(filePath => filePath.endsWith(\".json\"))\n        .map(async filePath => {\n          const doc = await readJsonFile<AnyDocument>(filePath)\n          if (!isRecord(doc) || typeof doc._id !== \"string\") {\n            throw new HTTPError(\n              `Project package contains an invalid doc in '${basename(filePath)}'.`,\n              400\n            )\n          }\n          return {\n            path: filePath,\n            resourceType: getResourceTypeForDocPath(tmpPath, filePath),\n            doc,\n          }\n        })\n    )\n\n    validateDependencyIndex(project, dependencyIndex, docs, manifest)\n\n    return {\n      tmpPath,\n      manifest,\n      project,","sourceCodeStart":998,"sourceCodeEnd":1034,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/projects/backups/imports.ts#L998-L1034","documentation":"Thrown while parsing each .json file in the package docs directory: a doc failed to parse into a record or lacks a string _id field. Every imported doc must be a CouchDB-style object with an _id, so a malformed or empty JSON file aborts the import.","triggerScenarios":"importProject with a package where a docs/*.json file is empty, truncated, an array instead of an object, valid JSON without an _id string property, or not JSON at all despite the .json extension.","commonSituations":"Manual edits to doc files that dropped _id; partial/corrupted download of the export; scripts writing JSON arrays of docs instead of one object per file; files renamed to .json without converting content.","solutions":["Open the file named in the error and ensure it is a JSON object containing a string _id","Re-download/re-export the package in case the file is truncated or corrupted","Validate every docs/*.json with jq: jq -e 'type == \"object\" and (._id | type == \"string\")' file.json","Regenerate the doc from the source workspace rather than hand-repairing it"],"exampleFix":"// before (docs/datasource-1.json)\n{\"name\": \"My DB\"}\n// after\n{\"_id\": \"datasource_ds_abc123\", \"name\": \"My DB\"}","handlingStrategy":"validation","validationCode":"const isDoc = (v: unknown): v is { _id: string } =>\n  typeof v === \"object\" && v !== null && \"_id\" in v && typeof (v as { _id: unknown })._id === \"string\"\nfor (const f of docFiles) {\n  const parsed = JSON.parse(await readFile(join(\"docs\", f), \"utf8\"))\n  if (!isDoc(parsed)) throw new Error(`${f} is not a valid doc`)\n}","typeGuard":"const isAnyDocument = (v: unknown): v is { _id: string } =>\n  typeof v === \"object\" && v !== null && \"_id\" in v && typeof (v as { _id: unknown })._id === \"string\"","tryCatchPattern":"try {\n  await sdk.projects.importProject(file)\n} catch (e) {\n  const m = String(e.message).match(/invalid doc in '(.+)'/)\n  if (m) console.error(`Fix ${m[1]}: must be an object with a string _id`)\n}","preventionTips":["Run jq validation on every docs/*.json before importing","Never hand-edit exported doc files; re-export instead","Verify the archive downloaded fully (checksum/size) before import"],"tags":["validation","import","project-package","http-400","json"],"backgroundTag":"project-package-validation-failed","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}