{"record":{"id":"4b12e756193e2565","repo":"can1357/oh-my-pi","slug":"invalid-empty-tar-member-path","errorCode":null,"errorMessage":"Invalid empty tar member path","messagePattern":"Invalid empty tar member path","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/tar.ts","lineNumber":747,"sourceCode":"\t\t\tmtime,\n\t\t\tdirectory ? 0o755 : 0o644,\n\t\t\tdirectory ? 0x35 : 0x30,\n\t\t),\n\t);\n\tif (!directory) appendPayload(parts, payload);\n}\n\n/** Encode files as a deterministic ustar archive, using PAX records for overflow paths. */\nexport async function encodeTar(members: Iterable<readonly [string, Uint8Array]>): Promise<Uint8Array> {\n\tconst parts: Uint8Array[] = [];\n\tconst kinds = new Map<string, \"directory\" | \"file\">();\n\tlet sequence = 0;\n\tfor (const [rawPath, bytes] of members) {\n\t\tconst directory = rawPath.endsWith(\"/\") || rawPath.endsWith(\"\\\\\");\n\t\tconst normalized = normalizeArchiveEntryPath(rawPath);\n\t\tif (!normalized) throw new ArchiveError(`Invalid tar member path '${formatArchivePathForError(rawPath)}'`);\n\t\tconst pathBytes = TEXT_ENCODER.encode(normalized);\n\t\tif (pathBytes.byteLength === 0) throw new ArchiveError(\"Invalid empty tar member path\");\n\t\tif (directory && bytes.byteLength !== 0) {\n\t\t\tthrow new ArchiveError(`Tar directory '${formatArchivePathForError(normalized)}' cannot contain file data`);\n\t\t}\n\t\tconst segments = normalized.split(\"/\");\n\t\tfor (let index = 1; index < segments.length; index++) {\n\t\t\tconst parent = segments.slice(0, index).join(\"/\");\n\t\t\tconst kind = kinds.get(parent);\n\t\t\tif (kind === \"file\")\n\t\t\t\tthrow new ArchiveError(`Tar member '${formatArchivePathForError(parent)}' is not a directory`);\n\t\t\tif (kind === \"directory\") continue;\n\t\t\tkinds.set(parent, \"directory\");\n\t\t\tappendTarEntry(parts, parent, new Uint8Array(0), true, sequence++);\n\t\t}\n\t\tconst existing = kinds.get(normalized);\n\t\tif (existing) {\n\t\t\tif (directory && existing === \"directory\") continue;\n\t\t\tthrow new ArchiveError(`Duplicate tar member path '${formatArchivePathForError(normalized)}'`);\n\t\t}","sourceCodeStart":729,"sourceCodeEnd":765,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/tar.ts#L729-L765","documentation":"After normalization the member path encoded to zero bytes, meaning the tar would contain a header with an empty name. Tar format requires a non-empty member name, so the encoder throws.","triggerScenarios":"Passing '' as a member key that survives normalization (e.g. an empty-string Map entry) — distinct from 3652, which fires when normalization returns nothing at all; the raw path normalized to something whose UTF-8 encoding is empty.","commonSituations":"Building a members map programmatically where a variable holding the path was empty; iterating a directory listing that included an empty relative path.","solutions":["Filter out empty-string keys from the members map before calling createTar","Default the member name to a fallback like 'file' when the source path is empty"],"exampleFix":"// before\nmembers.set(rawName ?? \"\", bytes);\n// after\nif (rawName) members.set(rawName, bytes);","handlingStrategy":"validation","validationCode":"for (const key of members.keys()) {\n\tif (key.trim().length === 0) throw new Error(`Empty member path`);\n}","typeGuard":"const hasNonEmptyPaths = (m: Map<string, Uint8Array>): boolean =>\n\t[...m.keys()].every((k) => k.length > 0);","tryCatchPattern":"try {\n\treturn await createTar(members);\n} catch (err) {\n\tif (err instanceof ArchiveError && err.message === \"Invalid empty tar member path\") {\n\t\t// drop or rename empty-keyed members\n\t}\n\tthrow err;\n}","preventionTips":["Filter empty-string keys from member maps before encoding","Give programmatic members an explicit fallback name"],"tags":["archive","tar","path-validation"],"backgroundTag":"invalid-archive-entry-path","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}