Skip to content

fix(189pc): handle numeric res_code in RenameResp to fix JSON unmarshal error#2489

Open
PIKACHUIM wants to merge 2 commits into
mainfrom
fix-189pc
Open

fix(189pc): handle numeric res_code in RenameResp to fix JSON unmarshal error#2489
PIKACHUIM wants to merge 2 commits into
mainfrom
fix-189pc

Conversation

@PIKACHUIM
Copy link
Copy Markdown
Member

fix(189pc): handle numeric res_code in RenameResp to fix JSON unmarshal error

Description / 描述

修复 189pc(天翼云盘)驱动在重命名(Rename)接口中,因服务端 res_code 字段返回数字类型导致 JSON 反序列化失败的问题。

  • drivers/189pc/types.goRenameResp.ResCode 字段类型由 string 修改为 any,使其能够兼容服务端返回的数字与字符串两种格式(与同文件中已有的 RespErr.ResCode 处理方式保持一致)。
  • 同步调整 drivers/189pc/driver.go 中对 ResCode 的字符串比较逻辑,先做类型断言再判断 "FileAlreadyExists",避免类型不匹配同时保持原有错误映射行为。

变更点

drivers/189pc/types.go

type RenameResp struct {
    ...
    Rev     string `json:"rev"`
    Size    int64  `json:"size"`
    ResCode any    `json:"res_code"` // int or string
}

drivers/189pc/driver.go

if err != nil {
    if code, ok := resp.ResCode.(string); ok && code == "FileAlreadyExists" {
        return nil, errs.ObjectAlreadyExists
    }
    return nil, err
}

Motivation and Context / 背景

线上日志中频繁出现以下报错,导致 189pc 重命名请求被 resty 重试并最终失败:

WARN  RESTY json: cannot unmarshal number into Go struct field RenameResp.res_code of type string, Attempt 1
ERROR RESTY json: cannot unmarshal number into Go struct field RenameResp.res_code of type string

天翼云盘的 rename 接口中,res_code 字段在不同业务场景下返回类型不一致:

  • 成功或部分错误场景返回数字(如 0
  • 已存在等业务错误场景返回字符串(如 "FileAlreadyExists"

而原 RenameResp.ResCode 被声明为 string,遇到数字返回值时反序列化直接失败,触发重试与错误日志。

实际上同一文件内的 RespErr.ResCode 早已使用 any 处理类似情况(注释为 居然有四种返回方式),本次修复将 RenameResp 对齐到该方案。

Relates to #XXXX

How Has This Been Tested? / 测试

  • 本地构建通过,无 lint 错误。
  • 在挂载 189pc 驱动的环境中执行重命名操作:
    • 重命名一个不存在冲突的文件 → res_code 为数字,JSON 反序列化正常,操作成功,错误日志消失。
    • 重命名为已存在的同名文件 → res_code"FileAlreadyExists",类型断言命中,返回 errs.ObjectAlreadyExists,行为与修复前保持一致。

Checklist / 检查清单

  • I have read the CONTRIBUTING document.
    我已阅读 CONTRIBUTING 文档。
  • I have formatted my code with go fmt or prettier.
    我已使用 go fmtprettier 格式化提交的代码。
  • I have added appropriate labels to this PR (or mentioned needed labels in the description if lacking permissions).
    我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
  • I have requested review from relevant code authors using the "Request review" feature when applicable.
    我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
  • I have updated the repository accordingly (If it's needed).
    我已相应更新了相关仓库(若适用)。

@PIKACHUIM PIKACHUIM requested a review from mkitsdts May 19, 2026 07:49
@PIKACHUIM PIKACHUIM added the bug label May 19, 2026
@PIKACHUIM PIKACHUIM changed the title fix(driver): fix 189 pc ResCode to any type fix(189pc): handle numeric res_code in RenameResp to fix JSON unmarshal error May 19, 2026
@mkitsdts
Copy link
Copy Markdown
Contributor

不好意思佬,之前疏忽了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants