{"record":{"id":"a66d35d2c31bb2f6","repo":"can1357/oh-my-pi","slug":"error-instanceof-error-error-message-string-er-a66d35","errorCode":null,"errorMessage":"error instanceof Error ? error.message : String(error)","messagePattern":"error instanceof Error \\? error\\.message : String\\(error\\)","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/rpm.ts","lineNumber":313,"sourceCode":"\t\tthrow new ArchiveError(`RPM package '${identity}' uses unsupported payload format '${metadata.payloadFormat}'`);\n\t}\n\n\tconst payloadOffset = mainHeaderOffset + mainIntro.totalSize;\n\tconst payloadSize = source.size - payloadOffset;\n\tassertInMemorySize(payloadSize, options.limits);\n\tconst payload = await readExact(source, payloadOffset, source.size, \"payload\");\n\tconst cpio = await decompressPayload(payload, metadata, identity, options.limits.maxInMemorySize);\n\tassertInMemorySize(cpio.byteLength, options.limits);\n\treturn readCpioEntriesFromBuffer(cpio, options);\n}\n\n/** Read an RPM lead, headers, compressed payload, and its contained CPIO entries. */\nexport const readRpm: FormatReader = async (source, options) => {\n\ttry {\n\t\treturn await readRpmArchive(source, options);\n\t} catch (error) {\n\t\tif (error instanceof ArchiveError) throw error;\n\t\tthrow new ArchiveError(error instanceof Error ? error.message : String(error));\n\t}\n};\n\n/** Detect the four-byte RPM package lead magic. */\nexport function sniffRpm(bytes: Uint8Array): boolean {\n\treturn bytes.byteLength >= 4 && bytes[0] === 0xed && bytes[1] === 0xab && bytes[2] === 0xee && bytes[3] === 0xdb;\n}\n","sourceCodeStart":295,"sourceCodeEnd":321,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/rpm.ts#L295-L321","documentation":"readRpm wraps readRpmArchive: any exception that is not already an ArchiveError (I/O failures, parse errors from helpers, out-of-memory from limits, etc.) is converted into an ArchiveError whose message is the original error's message. The literal shown is the expression used to build that message, so the surfaced text is whatever the underlying throw produced.","triggerScenarios":"Any non-ArchiveError throw inside readRpmArchive or its helpers: truncated reads from readExact, Uint8Array bounds violations, RangeError from size limit assertions, JSON/type errors in header parsing — all funnel through this wrapper.","commonSituations":"Reading from a short/closed stream that fails mid-read; feeding a non-RPM file that sniffs past magic but fails header validation; integer overflow / RangeError on absurd header sizes.","solutions":["Catch ArchiveError around readRpm and inspect error.message to see the wrapped root cause.","Verify the input source is a complete RPM (check magic 0xEDABEEDB and file size) before parsing.","Ensure the source stream (file, buffer) is readable and not closed/truncated mid-read."],"exampleFix":"// before\nconst entries = await readRpm(source);\n// after\ntry {\n  const entries = await readRpm(source);\n} catch (err) {\n  if (err instanceof ArchiveError) {\n    console.error(\"RPM parse failed:\", err.message); // may be a wrapped root cause\n  } else throw err;\n}","handlingStrategy":"try-catch","validationCode":"// verify RPM magic before reading\nfunction looksLikeRpm(bytes: Uint8Array): boolean {\n  return bytes.byteLength >= 4 && bytes[0] === 0xed && bytes[1] === 0xab && bytes[2] === 0xee && bytes[3] === 0xdb;\n}","typeGuard":"function isArchiveError(err: unknown): err is ArchiveError {\n  return err instanceof ArchiveError;\n}","tryCatchPattern":"try {\n  const entries = await readRpm(source);\n} catch (err) {\n  if (isArchiveError(err)) {\n    logger.error(\"RPM read failed\", { message: err.message }); // message may be a wrapped root cause\n  } else throw err;\n}","preventionTips":["Sniff the 0xEDABEEDB magic before calling readRpm","Ensure the source stream is fully readable and sized before parsing","Catch ArchiveError, not bare Error — non-ArchiveError throws get re-wrapped"],"tags":["rpm","error-wrapping","archive"],"backgroundTag":"archive-parse-failure","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}