{"record":{"id":"a75209aa6a78c029","repo":"dmtrKovalenko/fff","slug":"unknown-error","errorCode":null,"errorMessage":"Unknown error","messagePattern":"Unknown error","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/fff-node/src/ffi.ts","lineNumber":254,"sourceCode":"  }\n}\n\n/**\n * Read the FffResult envelope from a raw call. Returns the parsed struct + raw pointer.\n * On error, frees the result and returns a Result error.\n */\nfunction readResultEnvelope(\n  funcName: string,\n  paramsType: FieldType[],\n  paramsValue: unknown[],\n): { rawPtr: JsExternal; struct: FffResultRaw } | Result<never> {\n  loadLibrary();\n  const { rawPtr, struct: structData } = callRaw(funcName, paramsType, paramsValue);\n\n  if (structData.success === 0) {\n    const errorStr = readCString(structData.error);\n    freeResult(rawPtr);\n    return err(errorStr || \"Unknown error\");\n  }\n\n  return { rawPtr, struct: structData };\n}\n\n/** Call a function returning FffResult with void payload. */\nfunction callVoidResult(\n  funcName: string,\n  paramsType: FieldType[],\n  paramsValue: unknown[],\n): Result<void> {\n  const res = readResultEnvelope(funcName, paramsType, paramsValue);\n  if (\"ok\" in res) return res;\n  freeResult(res.rawPtr);\n  return { ok: true, value: undefined };\n}\n\n/** Call a function returning FffResult with int_value payload. */","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/dmtrKovalenko/fff/blob/7f8537e70f0ea1210f9acbbfc4640141105cdc78/packages/fff-node/src/ffi.ts#L236-L272","documentation":"readResultEnvelope converts the native FffResult envelope into a JS Result. When envelope.success is 0 it reads the native error string; if that string is empty or NULL it cannot recover a message and falls back to the generic 'Unknown error'.","triggerScenarios":"Any FFI call routed through readResultEnvelope whose native side failed without setting the error field, or the error pointer is null/unreadable.","commonSituations":"Calling a native function with arguments it does not validate (e.g. empty buffers), library/native binary version mismatch where error strings are not populated, or a genuinely empty error from the Rust side.","solutions":["Log/inspect the input arguments to the failing FFI call to find the invalid input","Rebuild the native library so native and JS bindings match (make build)","Report upstream: the native side should always set an error message on failure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":null,"tryCatchPattern":"const res = envelopeCall(...); if (!res.ok) { console.error('FFI failed:', res.error); /* fallback or rethrow with context */ }","preventionTips":["Keep the native binary and JS bindings on the same version","Log inputs to FFI calls to compensate for missing native error strings","Rebuild after upgrading the package"],"tags":["node","ffi","unknown-error"],"backgroundTag":"api-error-response","analyzedSha":"7f8537e70f0ea1210f9acbbfc4640141105cdc78","analyzedAt":"2026-09-10T07:26:53.407Z","contentChangedAt":"2026-09-10T07:26:53.407Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}