hmjz100/LinkSwift · error · Error

extra 缺少内容。

Error message

extra 缺少内容。

What it means

Thrown by the concurrent download manager (网盘直链下载助手.user.js:1345) when the caller passes an `extra` object that is missing or lacks the required fields `index`, `name`, and `size`. These fields drive task queueing and progress accounting, so the download is refused before starting. It is a strict input-shape validation of the download task descriptor.

Source

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

		/**
		 * 下载文件
		 * @author hmjz100
		 * @description 发送 GET 请求,一般用于文件下载,支持进度监控、自动重试、断点续传、非断回退
		 * @param {String} url - 请求地址
		 * @param {Object} headers - 请求头配置
		 * @param {Number} [size=0] - 响应类型
		 * @param {Object} [extra] - 附加参数(必须 `name`、`index`、`size` 属性;可选 `thread`、`retry` 属性)
		 * @returns {Promise} 包含响应数据的 `Promise` 对象
		 */
		async download(url, headers, extra) {
			headers = this.standHeaders(headers);
			// 初始化全局共享状态
			this.download.active = this.download.active || 0; // 全局活跃线程数
			this.download.taskCount = this.download.taskCount || 0; // 当前正在运行的 download 任务数
			const global_maxThreads = 10; // 整个允许的最大并发数

			if (extra) base.console.info(`【LinkSwift】Download\n收到数据:`, extra);
			if (!extra || !extra.index || !extra.name || !extra.size) throw new Error("extra 缺少内容。");

			const status = {
				aborted: false,
				requests: new Set(),
				results: [],
				active: 0,
				maxSpeed: 0,
				lastSampleTime: Date.now(),
				lastSampleLoaded: 0,
				currentSpeed: 0,
				totalLoaded: 0
			};

			const promise = new Promise((resolve, reject) => {
				(async () => {
					this.download.taskCount++; // 任务进入

					try {

View on GitHub (pinned to 417ea5e28a)

Solutions

  1. Ensure every task passed to the downloader includes non-empty `index`, `name`, and `size` fields.
  2. Normalize the data source: map API/parse results into the expected shape before calling the downloader.
  3. Log/guard the upstream list construction; filter out entries lacking these fields before enqueueing.
  4. If fields use alternate names, rename them to match the expected descriptor (`name`, `size`, `index`).

Example fix

// before
netdisk.download({ extra: { index: i, fileName: item.server_filename } })

// after
netdisk.download({ extra: { index: i, name: item.server_filename, size: Number(item.size) } })
Defensive patterns

Strategy: validation

Validate before calling

function isValidDownloadExtra(extra) {
  return !!extra && Number.isInteger(extra.index) && typeof extra.name === "string" && extra.name.length > 0 && typeof extra.size === "number" && extra.size > 0;
}
// call only if isValidDownloadExtra(extra)

Type guard

function isDownloadExtra(x) {
  return typeof x === "object" && x !== null
    && "index" in x && "name" in x && "size" in x
    && typeof x.index === "number" && typeof x.name === "string" && typeof x.size === "number";
}

Try / catch

try {
  await downloader.download({ extra });
} catch (e) {
  if (String(e.message).includes("extra 缺少内容")) {
    console.error("任务描述缺少 index/name/size:", extra); // fix the descriptor source
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the chunked download function with `extra` being undefined/null, or an object missing any of `index`, `name`, or `size` — e.g. building the descriptor manually from a file-list parser that omitted `size`, or passing an entry whose fields use different names (e.g. `fileName` instead of `name`).

Common situations: Custom/modified script forks that feed download tasks from a differently shaped data source; a network drive listing API change that returns items without `size`; calling the downloader programmatically with a partially initialized task object.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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