{"record":{"id":"f45652faccea3fe1","repo":"hmjz100/LinkSwift","slug":"error-f45652","errorCode":null,"errorMessage":"[光鸭云盘] 获取分享令牌失败","messagePattern":"\\[光鸭云盘\\] 获取分享令牌失败","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":7840,"sourceCode":"\t\t\tbase.registerMenuCommand();\r\n\t\t\tif (config.base.num === base.getValue(\"setting_init\").code || config.base.license === base.getValue(\"setting_init\").license) {\r\n\t\t\t\tthis.addButton();\r\n\t\t\t} else {\r\n\t\t\t\tthis.addInitButton();\r\n\t\t\t}\r\n\t\t\tthis.addPageListener();\r\n\t\t},\r\n\t};\r\n\r\n\t/**\r\n\t * 光鸭云盘\r\n\t * @author hmjz100\r\n\t */\r\n\tconst $guangya = {\r\n\t\taddPageListener() {\r\n\t\t\tthis.getShareToken(true).catch(e => {\r\n\t\t\t\tif (e instanceof Error) throw e;\r\n\t\t\t\tthrow new Error(e?.message || e || \"[光鸭云盘] 获取分享令牌失败\");\r\n\t\t\t});\r\n\t\t\t$doc.on(\"click\", \".listener-api-download.enhance\", async function (e) {\r\n\t\t\t\te.preventDefault();\r\n\t\t\t\tconst status = base._EventFactory(e);\r\n\t\t\t\tconst file = {\r\n\t\t\t\t\tindex: status.item.data(\"index\"),\r\n\t\t\t\t\tlink: status.item.data(\"link\"),\r\n\t\t\t\t\tname: status.item.data(\"name\"),\r\n\t\t\t\t\tsize: status.item.data(\"size\") || 0,\r\n\t\t\t\t}\r\n\t\t\t\tbase._resetData(file.index);\r\n\r\n\t\t\t\t// UI 初始化\r\n\t\t\t\tstatus.down_normal.hide();\r\n\t\t\t\tstatus.down_enhance.hide();\r\n\t\t\t\tstatus.down_idm.hide();\r\n\t\t\t\tstatus.link_message.hide();\r\n\t\t\t\tstatus.link_copy.hide();\r","sourceCodeStart":7822,"sourceCodeEnd":7858,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L7822-L7858","documentation":"Wrapper error in the 光鸭云盘 (Guangya Cloud) module's addPageListener: on page load it eagerly calls getShareToken(true) to pre-fetch a share token, and any non-Error rejection is re-thrown as '[光鸭云盘] 获取分享令牌失败'. The catch runs fire-and-forget (no await), so this error typically surfaces as an unhandled rejection on page load.","triggerScenarios":"Opening a Guangya share page triggers addPageListener -> getShareToken(true); if the underlying token flow rejects with a non-Error (raw JSON error, string, undefined), the wrapper fires — even before the user clicks download.","commonSituations":"Share ID missing/invalid on the page so token fetch fails; share expired or cancelled by owner; captcha token missing causing the internal flow to reject with a non-Error; network error surfacing as a non-Error rejection.","solutions":["Verify the share link is still valid and opens correctly in the browser","Reload the page to retrigger getShareToken with fresh state","Check console for the original rejection value to find the true cause (share id, captcha, or network)","Login/refresh captcha state in the userscript if the underlying flow reports auth problems"],"exampleFix":"// fire-and-forget with logging\nthis.getShareToken(true).catch(e => {\n  console.warn(\"[光鸭云盘] 分享令牌预取失败:\", e);\n});","handlingStrategy":"fallback","validationCode":"const shareId = extractShareId(location);\nif (!shareId) { console.warn('无有效 shareId，跳过分享令牌预取'); return; }","typeGuard":"function isError(e) { return e instanceof Error; }","tryCatchPattern":"try { await getShareToken(true); } catch (e) { shareTokenPromise = null; console.warn('分享令牌预取失败，将在下载时重试:', e); }","preventionTips":["Verify share links are valid before prefetching","Treat prefetch failure as non-fatal and fetch lazily on demand","Log original rejection payloads","Retry lazily on user download click instead of at page load"],"tags":["network","share-token","guangya","error-wrapping"],"backgroundTag":"non-error-rejection","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}