{"record":{"id":"5eff6a0427c0cdba","repo":"NousResearch/hermes-agent","slug":"file-is-empty","errorCode":null,"errorMessage":"File is empty","messagePattern":"File is empty","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"web/src/lib/session-import.ts","lineNumber":28,"sourceCode":"    Array.isArray((value as { sessions?: unknown }).sessions)\n      ? (value as { sessions: unknown[] }).sessions\n      : Array.isArray(value)\n        ? value\n        : [value];\n\n  const sessions = candidate.filter(\n    (item): item is ImportableSession =>\n      !!item && typeof item === \"object\" && !Array.isArray(item),\n  );\n  if (sessions.length !== candidate.length) {\n    throw new Error(\"Expected exported session JSON or JSONL\");\n  }\n  return sessions;\n}\n\nexport function parseImportSessions(text: string): ImportableSession[] {\n  const trimmed = text.trim();\n  if (!trimmed) throw new Error(\"File is empty\");\n\n  try {\n    return normalizeImportSessions(JSON.parse(trimmed));\n  } catch (jsonError) {\n    const lines = trimmed.split(/\\r?\\n/).filter((line) => line.trim());\n    if (lines.length <= 1) throw jsonError;\n    return normalizeImportSessions(lines.map((line) => JSON.parse(line)));\n  }\n}\n\nexport function importSummary(result: SessionImportResponse): string {\n  const parts = [`${result.imported} imported`];\n  if (result.skipped > 0) parts.push(`${result.skipped} skipped`);\n  if (result.detached > 0) {\n    parts.push(`${result.detached} detached from missing parents`);\n  }\n  return parts.join(\"; \");\n}","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/NousResearch/hermes-agent/blob/c896c09c42910c584c4c7d2325b58c14713ea42c/web/src/lib/session-import.ts#L10-L46","documentation":"parseImportSessions rejects with this when the imported file's text trims to zero length — there is nothing to parse as JSON or JSONL. It fires before JSON.parse is ever attempted, distinguishing an empty file from malformed content (which produces the parse error or 'Expected exported session JSON or JSONL').","triggerScenarios":"Selecting a 0-byte file in the session import UI; reading a file that failed to download fully; passing an empty string from a drag-and-drop handler that lost the payload.","commonSituations":"Interrupted downloads producing empty files; placeholder files created by touch; file-read races where the FileReader got an empty result.","solutions":["Verify the export file has content (non-zero size) and re-download/re-export if empty.","Check that the file-picker/drag-drop handler actually receives the File's bytes.","Show a file-size check in the UI before parsing."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (file.size === 0) {\n  showError('The selected file is empty — re-export and try again')\n  return\n}\nconst text = await file.text()\nif (!text.trim()) { showError('The selected file is empty'); return }","typeGuard":null,"tryCatchPattern":"try {\n  const sessions = parseImportSessions(text)\n} catch (err) {\n  if (String(err) === 'File is empty') { showError('Empty file — pick the real export'); return }\n  throw err\n}","preventionTips":["Check file.size > 0 at selection time.","Confirm downloads completed before importing.","Handle FileReader/drag-drop errors rather than passing empty strings along."],"tags":["import","file","sessions","validation"],"backgroundTag":null,"analyzedSha":"c896c09c42910c584c4c7d2325b58c14713ea42c","analyzedAt":"2026-08-14T17:18:01.089Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}