{"record":{"id":"923bc73ed935da4e","repo":"hcengineering/platform","slug":"no-data-to-export","errorCode":null,"errorMessage":"No data to export","messagePattern":"No data to export","errorType":"http","errorClass":"ApiError","httpStatus":400,"severity":"warning","filePath":"services/export/pod-export/src/server.ts","lineNumber":420,"sourceCode":"        config?: TransformConfig\n      } = req.body\n\n      if (_class == null) {\n        throw new ApiError(400, 'Missing required parameters')\n      }\n\n      const platformClient = await createPlatformClient(token)\n      const txOperations = new TxOperations(platformClient, socialId)\n\n      const exportDir = await fs.mkdtemp(join(tmpdir(), 'export-'))\n      let archiveDir: string | undefined\n      try {\n        const exporter = new WorkspaceExporter(measureCtx, txOperations, storageAdapter, wsIds, config)\n        await exporter.export(_class, exportDir, { format, attributesOnly: attributesOnly ?? false, query })\n\n        const files = await fs.readdir(exportDir)\n        if (files.length === 0) {\n          throw new ApiError(400, 'No data to export')\n        }\n\n        let exportedFile: string\n        if (files.length === 1) {\n          // Single space exported: return its file directly.\n          exportedFile = join(exportDir, files[0])\n        } else {\n          // Pack all spaces into a single archive so the sync endpoint can still return exactly one downloadable file.\n          archiveDir = await fs.mkdtemp(join(tmpdir(), 'export-archive-'))\n          const safeFormatToken = toSafeFormatFileToken(format)\n          const archiveName = `export-${wsIds.uuid}-${safeFormatToken}-${Date.now()}.zip`\n          exportedFile = join(archiveDir, archiveName)\n          await saveToArchive(exportDir, exportedFile)\n        }\n\n        await new Promise<void>((resolve, reject) => {\n          res.download(exportedFile, basename(exportedFile), (err) => {\n            if (err != null && !res.headersSent) {","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/export/pod-export/src/server.ts#L402-L438","documentation":"After WorkspaceExporter.export runs into a fresh temp directory, createServer lists the directory; if it is empty, nothing matched the requested _class/query, so it throws this 400 'No data to export'. The export itself did not fail — it simply produced zero files.","triggerScenarios":"Exporting a _class that has no documents in the workspace, or a query filter that matches nothing; exporting with attributesOnly into a workspace lacking that class's data.","commonSituations":"Typos in the _class string (silently matching nothing); overly restrictive DocumentQuery (wrong space, wrong ids); running against a fresh/empty test workspace; class renamed in a newer model version.","solutions":["Verify _class is spelled exactly as in the model and that documents of that class exist in the target workspace.","Relax or validate the query filter; first list documents of that class via the client API to confirm data exists.","Check you are pointed at the intended workspace (wsIds comes from the token's login info).","If multiple spaces export to separate files, confirm at least one space had matching data."],"exampleFix":"// before\nawait exporter.export('contact:Company', dir, { format: 'json', query: { space: 'wrong-space' } })\n// after\nawait exporter.export('contact:Company', dir, { format: 'json', query: { space: defaultSpaceId } })","handlingStrategy":"validation","validationCode":"const existing = await client.findAll(model.classRefs[_class], { limit: 1, ...query })\nif (existing.length === 0) {\n  console.warn(`No ${_class} documents match query; export would return 'No data to export'`)\n}","typeGuard":"null","tryCatchPattern":"try {\n  const file = await exportWorkspace({ _class, query })\n} catch (e) {\n  if (e instanceof ApiError && e.message === 'No data to export') {\n    return null // treat empty result as a valid, non-fatal outcome\n  }\n  throw e\n}","preventionTips":["Pre-check that the class exists in the workspace model and has matching documents.","Validate query filters (space ids, class names) against live data before exporting.","Treat 'empty export' as an expected branch in scheduled jobs, not a crash."],"tags":["export","http-400","empty-result","query"],"backgroundTag":"no-data-to-export","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}