{"record":{"id":"89a2208160831d19","repo":"agalwood/Motrix","slug":"magnetresolvefailed","errorCode":"MagnetResolveFailed","errorMessage":"saved torrent metadata is no longer available for task ${taskId}","messagePattern":"saved torrent metadata is no longer available for task (.+?)","errorType":"exception","errorClass":"AppError","httpStatus":null,"severity":"error","filePath":"src/core/torrent/magnet-tracker.ts","lineNumber":783,"sourceCode":"    if (metadataDir) {\n      try {\n        torrentBase64 = await this.readSavedTorrentBase64(metadataDir)\n        if (this.stopped) return\n      } catch (err) {\n        sourceError = err\n      }\n    }\n    if (torrentBase64 === undefined && pair.task.torrentMetaPath) {\n      try {\n        const bytes = await readFile(pair.task.torrentMetaPath)\n        torrentBase64 = bytes.toString('base64')\n        if (this.stopped) return\n      } catch (err) {\n        sourceError = err\n      }\n    }\n    if (torrentBase64 === undefined) {\n      throw new AppError(\n        ErrorCode.MagnetResolveFailed,\n        `saved torrent metadata is no longer available for task ${taskId}`,\n        sourceError\n      )\n    }\n\n    const meta = await this.torrentParser.parse(torrentBase64)\n    if (this.stopped) return\n    this.eventBus.emit(Events.MagnetFileSelection, {\n      taskId,\n      meta,\n      magnetUri,\n      torrentBase64,\n      saveDir,\n    })\n    log.info({ taskId }, 'magnet file selection reopened')\n  }\n","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/agalwood/Motrix/blob/1a708ee57746c434e2c67a44bbf0906a976afea4/src/core/torrent/magnet-tracker.ts#L765-L801","documentation":"Thrown by `reopenFileSelection` (magnet-tracker.ts:783) when neither the in-cache torrent base64 nor the on-disk `pair.task.torrentMetaPath` file could supply the metadata bytes (the read threw, captured as `sourceError`). The saved `.torrent` that backed the MetadataReady magnet is gone, so the file-selection window cannot be re-opened.","triggerScenarios":"The metadata cache entry was evicted AND the `.torrent` sidecar at torrentMetaPath was deleted/cleared (OS reboot wiped the temp dir, user cleaned the dir, disk error); torrentMetaPath points to an unmounted removable volume.","commonSituations":"OS reboot cleared the temp metadataDir; antivirus removed the `.torrent`; metadataDir moved/changed between runs; user manually deleted sidecars; storage failure.","solutions":["Re-acquire the magnet metadata (re-add the magnet URI to re-resolve) since the saved file is unrecoverable.","Move the metadata store to a stable, non-temp directory that survives reboots.","Confirm the metadataDir volume is mounted before re-opening selection.","Treat the task as unrecoverable for selection and inform the user to re-add."],"exampleFix":"// before\nif (torrentBase64 === undefined) {\n  throw new AppError(ErrorCode.MagnetResolveFailed, `saved torrent metadata is no longer available for task ${taskId}`, sourceError)\n}\n\n// after — attempt re-resolution from the magnet URI before failing\nif (torrentBase64 === undefined) {\n  if (pair.task.magnetUri) {\n    return this.reresolveMetadata(pair.task.magnetUri, taskId)\n  }\n  throw new AppError(ErrorCode.MagnetResolveFailed, `saved torrent metadata is no longer available for task ${taskId}`, sourceError)\n}","handlingStrategy":"fallback","validationCode":"async function metadataRecoverable(fs, torrentMetaPath) {\n  if (!torrentMetaPath) return false\n  try { await fs.access(torrentMetaPath, fs.constants.R_OK); return true } catch { return false }\n}","typeGuard":"function isMagnetResolveFailed(e) { return e instanceof AppError && e.code === ErrorCode.MagnetResolveFailed }","tryCatchPattern":"if (torrentBase64 === undefined) {\n  if (pair.task.magnetUri) {\n    return this.reresolveMetadata(pair.task.magnetUri, taskId) // fallback: re-resolve\n  }\n  throw new AppError(ErrorCode.MagnetResolveFailed, `saved torrent metadata is no longer available for task ${taskId}`, sourceError)\n}","preventionTips":["Store magnet sidecars in a stable, non-temp dir that survives reboots.","Keep an in-memory cache warm for MetadataReady tasks until selection completes.","Confirm the metadataDir volume is mounted before re-opening selection.","If unrecoverable, inform the user to re-add the magnet URI."],"tags":["magnet","metadata","filesystem","io","bittorrent"],"backgroundTag":null,"analyzedSha":"1a708ee57746c434e2c67a44bbf0906a976afea4","analyzedAt":"2026-08-12T16:18:09.346Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}