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

Aperta
#137 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
fastapi, python
Ambito
api, backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).
Lingua principale
Python
Stelle
1
Fork
1
Merge medio
4h 46m
PR unite (30g)
55

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di falbany/ProFiles

Tutte le issue di falbany/ProFiles

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.