@tiens.nguyen/gonext-local-worker 1.0.93 → 1.0.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,6 +23,7 @@ import contextlib
23
23
  import json
24
24
  import re
25
25
  import sys
26
+ import traceback
26
27
  import urllib.request
27
28
  import urllib.error
28
29
 
@@ -435,6 +436,11 @@ def _pdf_upload_via_api(api_base: str, worker_key: str, file_name: str,
435
436
  except _ue.HTTPError as e: # noqa: PERF203
436
437
  detail = e.read().decode("utf-8", "replace")[:300]
437
438
  raise RuntimeError(f"Could not get a PDF upload URL (HTTP {e.code}): {detail}")
439
+ except _ue.URLError as e:
440
+ raise RuntimeError(
441
+ f"Could not reach the API at {base} to presign the upload "
442
+ f"({getattr(e, 'reason', e)}). Is the worker API deployed/online?"
443
+ )
438
444
  put_url = ref.get("putUrl")
439
445
  get_url = ref.get("getUrl")
440
446
  if not put_url or not get_url:
@@ -451,7 +457,10 @@ def _pdf_upload_via_api(api_base: str, worker_key: str, file_name: str,
451
457
  if up.status not in (200, 201, 204):
452
458
  raise RuntimeError(f"S3 upload failed (HTTP {up.status}).")
453
459
  except _ue.HTTPError as e: # noqa: PERF203
454
- raise RuntimeError(f"S3 upload failed (HTTP {e.code}).")
460
+ detail = e.read().decode("utf-8", "replace")[:200]
461
+ raise RuntimeError(f"S3 upload failed (HTTP {e.code}): {detail}")
462
+ except _ue.URLError as e:
463
+ raise RuntimeError(f"S3 upload could not connect ({getattr(e, 'reason', e)}).")
455
464
  return get_url
456
465
 
457
466
 
@@ -807,13 +816,24 @@ def run_agent_chat(cfg):
807
816
  )
808
817
 
809
818
  # 2) Render the Markdown to PDF bytes locally (pure-Python xhtml2pdf).
819
+ # Catch EVERYTHING (xhtml2pdf can raise arbitrary errors on exotic glyphs /
820
+ # emoji), so the tool always returns a string and never breaks the single shot.
810
821
  _emit({"type": "step", "text": "Rendering PDF…"})
811
822
  try:
812
823
  pdf_bytes = _render_pdf_bytes(markdown_text, doc_title)
813
824
  except RuntimeError as e:
814
- # Engine missing or render failure — surface the (self-explaining) message.
825
+ # Engine missing or a clean render failure — surface the message as-is.
815
826
  msg = str(e)
816
- _log(f"create_pdf render error: {msg[:120]}")
827
+ _log(f"create_pdf render error: {msg[:200]}")
828
+ _last_obs["text"] = msg
829
+ return msg
830
+ except Exception as e: # noqa: BLE001 — unexpected render crash
831
+ _log(f"create_pdf render crash: {type(e).__name__}: {e!r}\n{traceback.format_exc()}")
832
+ msg = (
833
+ "Sorry — I couldn't render that text into a PDF "
834
+ f"({type(e).__name__}: {str(e)[:160]}). "
835
+ "Try simpler text without unusual symbols/emoji."
836
+ )
817
837
  _last_obs["text"] = msg
818
838
  return msg
819
839
 
@@ -824,9 +844,9 @@ def run_agent_chat(cfg):
824
844
  download_url = _pdf_upload_via_api(
825
845
  pdf_api_base, pdf_worker_key, file_name, pdf_bytes
826
846
  )
827
- except RuntimeError as e:
828
- msg = f"PDF was created but could not be uploaded: {e}"
829
- _log(f"create_pdf upload error: {str(e)[:120]}")
847
+ except Exception as e: # noqa: BLE001 — network / API errors must not crash the tool
848
+ _log(f"create_pdf upload error: {type(e).__name__}: {e!r}\n{traceback.format_exc()}")
849
+ msg = f"PDF was created but could not be uploaded: {str(e)[:200]}"
830
850
  _last_obs["text"] = msg
831
851
  return msg
832
852
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiens.nguyen/gonext-local-worker",
3
- "version": "1.0.93",
3
+ "version": "1.0.94",
4
4
  "description": "Polls GoNext cloud API for async local LLM jobs and runs them against Ollama/OpenAI-compatible servers on this Mac",
5
5
  "type": "module",
6
6
  "license": "MIT",