Skip to content

fix(139): throw instead of silently break when folder not found in path - #121

Open
PIKACHUIM wants to merge 1 commit into
mainfrom
fix/139-resolve-catalog-id-silent-fallback
Open

PIKACHUIM wants to merge 1 commit into
mainfrom
fix/139-resolve-catalog-id-silent-fallback

Conversation

@PIKACHUIM

Copy link
Copy Markdown
Member

fix(139): throw instead of silently break when folder not found in path

问题描述

挂载 139 云盘并访问子目录(例如 /DISK1-4T/139)时,文件列表始终返回根目录内容,无法正常列出子目录文件。

根本原因

resolveCatalogId() 负责将虚拟路径逐段解析为实际的 catalogID。当某个路径段在文件夹列表中找不到时,原代码使用 break 静默退出循环:

// 修复前
if (foundFolder) {
  currentCatalogId = foundFolder.catalogID
} else {
  break  // ← 静默退出,currentCatalogId 仍为根目录 ID
}

break 会让方法悄无声息地返回当前已解析到的最后一个有效 catalogId(通常就是根目录),导致 list() 和 get() 表面上返回 200,但内容是根目录而非目标路径,用户完全无从得知出了什么问题。

常见触发场景:存储配置的 type 字段未填写(应填 personal 或 personal_new),导致 API 版本选错,文件夹列表为空,路径第一段即匹配失败。

修复方案

将 break 改为 throw,附带明确的错误信息(包含未找到的路径段名称和完整路径):

// 修复后
if (foundFolder) {
  currentCatalogId = foundFolder.catalogID
} else {
  throw new Error(
    `[139] folder not found: "${part}" in path "${physicalPath}"`,
  )
}

修复效果

  • 路径解析失败时,list() / get() 返回明确的错误,前端提示错误而非显示错误内容
  • 日志中可以直接看到是哪个路径段找不到,方便用户自查账号类型配置是否正确
  • 行为与其他驱动一致(找不到路径应报错,而非降级)

变更范围

文件 变更
src/backend/drivers/139/driver.ts break → throw new Error(...) (+3/-1)

测试

  • 配置正确的 139 账号:路径解析成功,行为与修复前相同 ✅
  • 配置错误(type 字段留空的老账号):之前返回根目录,现在返回明确错误 ✅

关联

复现环境:https://openlist-web-dpw1236efa31.edgeone.cool/139/DISK1-4T/139

@PIKACHUIM PIKACHUIM linked an issue Oct 11, 2026 that may be closed by this pull request
4 tasks done
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
openlist-work ee136b6 Oct 11 2026, 05:55 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
openlist-tsworkers ee136b6 Oct 11 2026, 05:57 AM

@pikachuren
pikachuren force-pushed the fix/139-resolve-catalog-id-silent-fallback branch from 1edbbde to d122278 Compare October 11, 2026 05:49
…l results

1. drivers/139/driver.ts — resolveCatalogId() used `break` when a path
   segment was not found in the folder listing, silently returning the
   last successfully resolved catalogId (typically the root).  list()
   and get() then appeared to succeed but returned root directory
   contents for any path whose intermediate folder could not be matched,
   producing the 'always shows root' symptom.  Changed to `throw` with
   a message that includes the missing segment and full path so
   misconfigured account types are immediately visible in logs.

2. server/fs.ts — when resolvePath() returns isVirtual=true the storage
   object is null and cacheExpiration was set to `undefined`.  The front
   end interprets undefined as a non-zero TTL and caches the Virtual
   result; subsequent requests hit the cache and keep showing the Virtual
   provider even after the real storage comes online.  Fixed by returning
   0 for Virtual paths so the front end never caches them.
@pikachuren
pikachuren force-pushed the fix/139-resolve-catalog-id-silent-fallback branch from d122278 to ee136b6 Compare October 11, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 移动云盘访问子目录出现根目录套娃情况

2 participants