zai-org / zai-org/feedback

[Bug] 长文本粘贴在 web-remote 模式下失败:Failed to read attachment: [object Object]

Open
#351 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: P2
Dominant language
No language data
Stars
22
Forks
1
PR merge metrics
No merged PRs in 30d

Description

问题描述 / Description

在 web-remote(远程浏览器访问)模式下,当粘贴 ≥ 5120 字符的长文本到聊天输入框时,显示错误:Failed to read attachment: [object Object],文本无法插入。

短文本(< 5120 字符)正常。

复现步骤 / Steps to reproduce

  1. 打开 ZCode web-remote(浏览器远程访问桌面端)
  2. 进入聊天界面
  3. 复制 ≥ 5120 字符的纯文本
  4. 在消息输入框中粘贴(Ctrl+V)

期望行为 / Expected behavior

长文本应正常插入输入框,或自动转为临时 .txt 文件附件。

实际行为 / Actual behavior

显示红色错误横幅:Failed to read attachment: [object Object],无文本插入。

根因分析 / Root cause

通过反编译 app.asar 定位到以下代码路径:

// 阈值常量
var DMe = 5 * 1024;  // 5120 字符
function MMe(e) { return e.length >= DMe; }

// 粘贴处理
MMe(n) && (async () => {
  try {
    let e = await f.createTempTextAttachment?.({text: n, filename: NMe()});
    if (!e) throw Error('当前平台不支持临时文本附件');
    z([jMe(n, e)]);
  } catch (e) {
    T(m.formatMessage({id: 'chat.attachments.readFailed'}, {
      message: e instanceof Error ? e.message : String(e)  // ← 问题在这里
    }));
  }
})()

两层问题:

  1. 错误序列化丢失原型:在 web-remote 模式下,createTempTextAttachment 调用通过 websocket 桥接到桌面端执行。当桌面端 wh() 函数(创建临时 .txt 文件)抛出错误时,错误经过 IPC/websocket 序列化后,Error 原型丢失,变成 plain object。

  2. catch 块未处理非 Error 对象e instanceof Error === false 时执行 String(e),对任何对象返回 [object Object]

建议修复 / Proposed fix

修复 1(UI 防御性处理):

message: e instanceof Error
  ? e.message
  : (e?.message ?? (typeof e === 'string' ? e : JSON.stringify(e)))

修复 2(桥接层结构修复): 确保 websocket/IPC 桥接序列化错误时保留 messagename 字段,接收端重建 Error 对象。

修复 3(根因): 调查 wh() 在 web-remote 模式下抛出的真实原因(可能是临时目录权限、路径序列化问题、或 wx 标志的 EEXIST 竞争)。

环境 / Environment

  • ZCode 版本:3.9.1.5853
  • 设备/系统:Windows 10 22631
  • 浏览器:Chrome(web-remote 模式)
  • 复现频率:Always(每次 ≥ 5120 字符必现)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the web-remote paste path in the decompiled app.asar, especially MMe, createTempTextAttachment, the catch block, and the desktop wh() function. Reproduce the failure with text at least 5120 characters long and verify that long text is inserted or attached while failures expose a useful message instead of [object Object].

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
desktop-dev, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.