Skip to content

Commit ca4d112

Browse files
committed
show rendering errors
1 parent 2308de0 commit ca4d112

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

paperworks/lib/server.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ def _render_worker():
136136
batch = _render_queue.get()
137137
cfg = load_config()
138138
style_name = cfg.get("style", "wg21")
139-
out_dir = Path(cfg.get("output_dir", ""))
139+
out_dir_str = cfg.get("output_dir", "")
140+
if not out_dir_str:
141+
_add_log("render", "Output directory not configured", status="error")
142+
continue
143+
out_dir = Path(out_dir_str)
140144
if not out_dir.is_dir():
141-
_add_log("render", f"Output directory not set or missing", status="error")
145+
_add_log("render", f"Output directory not found: {out_dir_str}", status="error")
142146
continue
143147

144148
try:
@@ -206,11 +210,14 @@ def _flush_md_pending():
206210
return
207211
cfg = load_config()
208212
out_dir = cfg.get("output_dir", "")
209-
out_path = Path(out_dir) if out_dir else None
213+
if not out_dir:
214+
_add_log("render", "Output directory not configured; skipping auto-render", status="error")
215+
return
216+
out_path = Path(out_dir)
210217
batch = []
211218
for md_path in candidates:
212219
md = Path(md_path)
213-
if out_path and out_path.is_dir():
220+
if out_path.is_dir():
214221
pdf = out_path / md.with_suffix(".pdf").name
215222
if pdf.is_file() and pdf.stat().st_mtime >= md.stat().st_mtime:
216223
continue
@@ -564,6 +571,17 @@ def render_paper():
564571
md_path = data.get("md_path", "")
565572
if not md_path or not Path(md_path).is_file():
566573
return jsonify({"error": "Markdown file not found"}), 400
574+
cfg = load_config()
575+
out_dir = cfg.get("output_dir", "")
576+
if not out_dir or not Path(out_dir).is_dir():
577+
_add_log("render", "Output directory not configured or missing", status="error")
578+
_broadcast("rendered", {
579+
"file": md_path, "status": "error",
580+
"error": "Output directory not configured or missing",
581+
"done": 1, "total": 1,
582+
})
583+
_broadcast("render_done", {"total": 1, "done": 0, "errors": 1})
584+
return jsonify({"error": "Output directory not configured or missing"}), 400
567585
_render_queue.put([md_path])
568586
_add_log("render", f"Queued: {Path(md_path).name}")
569587
return jsonify({"ok": True})
@@ -625,7 +643,10 @@ def render_all():
625643
"""Queue only markdown files whose PDF is missing or stale."""
626644
cfg = load_config()
627645
output_dir = cfg.get("output_dir", "")
628-
out_path = Path(output_dir) if output_dir else None
646+
if not output_dir or not Path(output_dir).is_dir():
647+
_add_log("render", "Output directory not configured or missing", status="error")
648+
return jsonify({"error": "Output directory not configured or missing"}), 400
649+
out_path = Path(output_dir)
629650

630651
batch = []
631652
for entry in cfg.get("watch_dirs", []):
@@ -638,10 +659,9 @@ def render_all():
638659
for md in mds:
639660
if not md.is_file():
640661
continue
641-
if out_path and out_path.is_dir():
642-
pdf = out_path / md.with_suffix(".pdf").name
643-
if pdf.is_file() and pdf.stat().st_mtime >= md.stat().st_mtime:
644-
continue
662+
pdf = out_path / md.with_suffix(".pdf").name
663+
if pdf.is_file() and pdf.stat().st_mtime >= md.stat().st_mtime:
664+
continue
645665
batch.append(str(md))
646666

647667
if not batch:

paperworks/lib/templates/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,8 @@ <h2>Activity Log</h2>
635635
es.addEventListener('render_done',e=>{
636636
const d=JSON.parse(e.data);
637637
endWork('btn-render', null);
638-
setStatus('ready',`Rendered ${d.done||0} file${(d.done||0)!==1?'s':''}`);
638+
if(d.errors&&!d.done){setStatus('error','Render failed: check log for details');}
639+
else{setStatus('ready',`Rendered ${d.done||0} file${(d.done||0)!==1?'s':''}`);}
639640
setTimeout(()=>setStatus('ready','Ready'),4000);
640641
loadInventory();
641642
});

0 commit comments

Comments
 (0)