server: config save/content endpoints convert OSError and UnicodeDecodeError into raw 500s; inconsistent missing-file semantics (400/404/200)

未关闭
#137 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
fastapi, python
领域
api, backend

调研方向

Read the config endpoints in routes/config.py at the cited locations for /load, /reload, /content, /save, and /save-as, then check the ValidationIssue[] contract in client.ts:36-54. Trace the read, decode, and write failures alongside the existing status responses. Done means the endpoints handle these failures consistently and the validation response shape follows the documented contract; the issue leaves the exact error status choice open.

由索引模型根据 Issue 内容生成。

描述

bug

Problem

Error handling across the config endpoints is inconsistent and leaks tracebacks:

  • save_config_endpoint: on_disk_hash = content_hash(config_path.read_text(encoding="utf-8")) (routes/config.py:458) — raises UnicodeDecodeError/OSError → unhandled 500 before the staleness guard can answer 409. write_text_atomic(config_path, payload.content) (config.py:471) raises OSError on read-only target/full disk → raw 500 traceback instead of an actionable 4xx; same in save_as_config_endpoint (config.py:540).
  • GET /content's config_path.read_text(encoding="utf-8") (config.py:405) 500s on non-UTF-8 files.
  • Missing-file semantics for the same situation differ per endpoint: /load → 400 (config.py:171), /content → 404 (config.py:400-403), /reload → 200 {"reloaded": false} (config.py:337-339).
  • Validation-failure shape is heterogeneous: /save and /save-as put the issue list in detail (HTTPException(400, detail=issues)) while every other 4xx uses a string, and /validate returns the same data as a 200 body — three shapes for one concern (the client compensates in apiError(), client.ts:36-54).

Suggested fix

  1. Wrap the write/read calls in try/except OSError as e: raise HTTPException(422 or 500-with-detail, f"Cannot write configuration file: {e}").
  2. Pick one missing-file status (404) for all three endpoints.
  3. Keep the list-detail 400s but document them in one place (they are already the ValidationIssue[] contract in client.ts).
主要语言
Python
星标
1
派生
1
平均合并
4 小时 46 分钟
30 天内合并 PR
55

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

falbany/ProFiles 的其他 Issue

查看 falbany/ProFiles 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。