Spaces:
Sleeping

Piers Lyon Claude Opus 4.7 (1M context) commited on
Commit
b189beb
·
1 Parent(s): 482374c

Surface the real HF Hub error in state_sync logs

Browse files

The Space's container log was showing
[state_sync] pull error: Force download failed due to the above error.
which is huggingface_hub's wrapper exception with no detail. The actual
HTTP error (401 / 403 / 404) lives on the inner exception and was being
swallowed.

Patch:
- HfHubHTTPError handler now also prints the HTTP status code (so
401 vs 403 vs 404 are obvious at a glance — different fixes for
each).
- Generic Exception handler now prints the full traceback AND a
one-line summary of the call args (repo, token length, token
prefix). No secret leakage — only length and the first 4 chars.

This lets the next Space restart self-diagnose: if the log shows
HTTP 401 → the Space's HF_TOKEN is invalid (rotate it).
HTTP 403 → the token exists but lacks read scope on the dataset.
HTTP 404 → HF_STATE_REPO points to a non-existent dataset.
Anything else → the traceback will tell us.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. state_sync.py +20 -2
state_sync.py CHANGED
@@ -169,12 +169,30 @@ def pull_state(verbose: bool = False, force: bool = False) -> bool:
169
  return False
170
  _state["last_error"] = f"pull: {msg}"
171
  if verbose:
172
- print(f"[state_sync] pull error: {msg}", flush=True)
 
 
 
 
 
 
173
  return False
174
  except Exception as e:
175
  _state["last_error"] = f"pull: {type(e).__name__}: {e}"
176
  if verbose:
177
- print(f"[state_sync] pull error: {e}", flush=True)
 
 
 
 
 
 
 
 
 
 
 
 
178
  return False
179
 
180
  # Replace local DB with downloaded copy
 
169
  return False
170
  _state["last_error"] = f"pull: {msg}"
171
  if verbose:
172
+ print(f"[state_sync] pull error (HfHubHTTPError): {msg}", flush=True)
173
+ # status_code is on the underlying response — surface it so
174
+ # 401 (bad token) / 403 (no read) / 404 (wrong repo) are
175
+ # immediately distinguishable from each other in the log.
176
+ sc = getattr(getattr(e, "response", None), "status_code", None)
177
+ if sc is not None:
178
+ print(f"[state_sync] HTTP status: {sc}", flush=True)
179
  return False
180
  except Exception as e:
181
  _state["last_error"] = f"pull: {type(e).__name__}: {e}"
182
  if verbose:
183
+ # str(e) on wrapper exceptions (LocalEntryNotFoundError etc.)
184
+ # is often "Force download failed due to the above error." with
185
+ # no useful detail. Print the full traceback so the underlying
186
+ # cause (which the wrapper hid) is visible in the Space logs.
187
+ import traceback as _tb
188
+ print(f"[state_sync] pull error: {type(e).__name__}: {e}", flush=True)
189
+ print("[state_sync] traceback:", flush=True)
190
+ _tb.print_exc()
191
+ # Also log a few high-signal facts about the call so we don't
192
+ # need to scroll to figure out which repo / token / dest was
193
+ # in play.
194
+ print(f"[state_sync] repo={repo} token_len={len(token) if token else 0} "
195
+ f"token_prefix={token[:4]+'…' if token else 'MISSING'}", flush=True)
196
  return False
197
 
198
  # Replace local DB with downloaded copy