OdysseusYuan/LKY_OfficeTools · error · Exception

下载 {a} 异常!

Error message

下载 {a} 异常!

What it means

Thrown when Lib_Aria2c.DownFile returns a value other than 1. DownFile returns 1 on success, 0 when the aria2c binary (lot_aria2c.exe) is missing from the SDK path, and -1 when Com_ExeOS.Run.Exe fails to launch the process (sentinel -920921) or any other exception occurs. The source comment confirms this is designed to abort when the core download engine is lost. Note: genuine download failures where aria2c exits non-zero but the process launched are NOT caught — DownFile still returns 1 because it only checks the launcher sentinel, not aria2c's own exit code.

Source

Thrown at LKY_OfficeTools/Lib/Lib_OfficeDownload.cs:51

                Thread.Sleep(1000);

                //轮询下载所有文件
                foreach (var a in OfficeNetInfo.OfficeFileList)
                {
                    //根据官方目录,来调整下载保存位置
                    string save_path = save_to + a.Substring(OfficeNetInfo.OfficeUrlRoot.Length).Replace("/", "\\");

                    //保存到List里面,用于后续检查
                    save_files.Add(save_path);

                    new Log($"\n     >> 下载 {new FileInfo(save_path).Name} 文件中,请稍候 ...", ConsoleColor.DarkYellow);

                    //遇到重复的文件可以断点续传
                    int down_result = Lib_Aria2c.DownFile(a, save_path);
                    if (down_result != 1)
                    {
                        //如果因为核心下载exe丢失,导致下载失败,直接中止
                        throw new Exception($"下载 {a} 异常!");
                    }

                    //如果用户中断了下载,则直接跳出
                    if (Lib_AppState.Current_StageType == Lib_AppState.ProcessStage.Interrupt)
                    {
                        return -1;
                    }

                    new Log($"     √ 已下载 {new FileInfo(save_path).Name} 文件。", ConsoleColor.DarkGreen);
                }

                new Log($"\n------> 正在检查 Office v{OfficeNetInfo.OfficeLatestVersion} 文件 ...", ConsoleColor.DarkCyan);

                foreach (var b in save_files)
                {
                    string aria_tmp_file = b + ".aria2c";

                    //下载完成的标志:文件存在,且不存在临时文件

View on GitHub (pinned to 6f9a1bd471)

Solutions

  1. Verify lot_aria2c.exe exists at Documents.SDKs.SDKs_Root + @"\Aria2c\lot_aria2c.exe" and is executable.
  2. Re-extract or re-download the SDK bundle to restore the missing binary.
  3. Add the SDK directory to antivirus exclusions if the binary keeps disappearing.
  4. Confirm SDKs_Root resolves to the correct absolute path for the current install.
  5. If down_result is -1 (launcher exception), inspect the Log output for the Run.Exe failure cause.

Example fix

// before
int down_result = Lib_Aria2c.DownFile(a, save_path);
if (down_result != 1)
{
    throw new Exception($"下载 {a} 异常!");
}

// after — distinguish the two failure codes for actionable messages
int down_result = Lib_Aria2c.DownFile(a, save_path);
if (down_result == 0)
{
    throw new Exception($"下载引擎 aria2c 丢失,请重新提取 SDK 后重试。");
}
if (down_result == -1)
{
    throw new Exception($"下载 {a} 失败:引擎无法启动,请查看日志。");
}
Defensive patterns

Strategy: validation

Validate before calling

// Verify the aria2c binary exists before entering the download loop.
string aria2c_path = Documents.SDKs.SDKs_Root + @"\Aria2c\lot_aria2c.exe";
if (!File.Exists(aria2c_path))
{
    new Log($"下载引擎丢失:{aria2c_path},请重新提取 SDK。", ConsoleColor.DarkRed);
    // trigger SDK re-extraction or abort the batch before any DownFile call
    return;
}

Try / catch

// Wrap the per-file download so one failure gives an actionable message without masking the cause.
try
{
    int down_result = Lib_Aria2c.DownFile(a, save_path);
    if (down_result == 0) throw new Exception($"aria2c 引擎丢失:{aria2c_path}");
    if (down_result == -1) throw new Exception($"引擎启动失败,下载 {a}");
}
catch (Exception ex)
{
    new Log($"下载 {a} 失败:{ex.Message}", ConsoleColor.DarkRed);
    // decide: retry, skip, or abort the whole batch
}

Prevention

When it happens

Trigger: DownFile returns 0 when Documents\SDKs\Aria2c\lot_aria2c.exe does not exist on disk, or -1 when Run.Exe cannot start the aria2c process (returns -920921) or throws. Both make the caller's `down_result != 1` branch throw.

Common situations: The SDK bundle was not extracted; antivirus quarantined lot_aria2c.exe; the SDKs_Root path points to a wrong location; a partial/corrupted install left the binary absent; permissions prevent executing the exe.

Related errors


AI-assisted analysis of OdysseusYuan/LKY_OfficeTools@6f9a1bd471 (2026-08-13). Data as JSON: /api/errors/7018c973a1c9ef23. Report an issue: GitHub.