hmjz100/LinkSwift · error · Error

[光鸭云盘] 获取分享令牌失败

Error message

[光鸭云盘] 获取分享令牌失败

What it means

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.

Source

Thrown at (改)网盘直链下载助手.user.js:7840

			base.registerMenuCommand();
			if (config.base.num === base.getValue("setting_init").code || config.base.license === base.getValue("setting_init").license) {
				this.addButton();
			} else {
				this.addInitButton();
			}
			this.addPageListener();
		},
	};

	/**
	 * 光鸭云盘
	 * @author hmjz100
	 */
	const $guangya = {
		addPageListener() {
			this.getShareToken(true).catch(e => {
				if (e instanceof Error) throw e;
				throw new Error(e?.message || e || "[光鸭云盘] 获取分享令牌失败");
			});
			$doc.on("click", ".listener-api-download.enhance", async function (e) {
				e.preventDefault();
				const status = base._EventFactory(e);
				const file = {
					index: status.item.data("index"),
					link: status.item.data("link"),
					name: status.item.data("name"),
					size: status.item.data("size") || 0,
				}
				base._resetData(file.index);

				// UI 初始化
				status.down_normal.hide();
				status.down_enhance.hide();
				status.down_idm.hide();
				status.link_message.hide();
				status.link_copy.hide();

View on GitHub (pinned to 417ea5e28a)

Solutions

  1. Verify the share link is still valid and opens correctly in the browser
  2. Reload the page to retrigger getShareToken with fresh state
  3. Check console for the original rejection value to find the true cause (share id, captcha, or network)
  4. Login/refresh captcha state in the userscript if the underlying flow reports auth problems

Example fix

// fire-and-forget with logging
this.getShareToken(true).catch(e => {
  console.warn("[光鸭云盘] 分享令牌预取失败:", e);
});
Defensive patterns

Strategy: fallback

Validate before calling

const shareId = extractShareId(location);
if (!shareId) { console.warn('无有效 shareId,跳过分享令牌预取'); return; }

Type guard

function isError(e) { return e instanceof Error; }

Try / catch

try { await getShareToken(true); } catch (e) { shareTokenPromise = null; console.warn('分享令牌预取失败,将在下载时重试:', e); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hmjz100/LinkSwift@417ea5e28a (2026-09-02). Data as JSON: /api/errors/f45652faccea3fe1. Report an issue: GitHub.