{"record":{"id":"2040d513dd0dde93","repo":"jackwener/OpenCLI","slug":"hf-spaces-request-failed-err-message-err","errorCode":null,"errorMessage":"hf spaces request failed: ${err?.message ?? err}","messagePattern":"hf spaces request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/hf/spaces.js","lineNumber":62,"sourceCode":"            throw new ArgumentError(`hf spaces sdk must be one of gradio / streamlit / docker / static`);\n        }\n\n        const url = new URL('https://huggingface.co/api/spaces');\n        url.searchParams.set('sort', sort);\n        url.searchParams.set('direction', '-1');\n        url.searchParams.set('limit', String(limit));\n        url.searchParams.set('full', 'true');\n        if (args.search) url.searchParams.set('search', String(args.search));\n        if (sdk) url.searchParams.set('sdk', sdk);\n\n        let resp;\n        try {\n            resp = await fetch(url, {\n                headers: { Accept: 'application/json', 'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)' },\n            });\n        }\n        catch (err) {\n            throw new CommandExecutionError(`hf spaces request failed: ${err?.message ?? err}`);\n        }\n        if (resp.status === 429) {\n            throw new CommandExecutionError(\n                'hf spaces returned HTTP 429 (rate limited)',\n                'Hugging Face throttles unauthenticated traffic; wait a few seconds and retry.',\n            );\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`hf spaces failed: HTTP ${resp.status}`);\n        }\n        let data;\n        try {\n            data = await resp.json();\n        }\n        catch (err) {\n            throw new CommandExecutionError(`hf spaces returned malformed JSON: ${err?.message ?? err}`);\n        }\n        const list = Array.isArray(data) ? data : [];","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/spaces.js#L44-L80","documentation":"This error wraps any low-level failure of the fetch() call made by the `hf spaces` command to the Hugging Face Spaces listing API. The library throws a CommandExecutionError with the underlying network error's message so the CLI user sees why the HTTP request never completed. It is a network/transport-level failure, not an HTTP status error.","triggerScenarios":"The fetch() to https://huggingface.co/api/spaces throws: DNS resolution failure, connection refused/reset, TLS errors, request timeouts, or an offline machine. Any exception thrown by fetch itself (not an HTTP error status) is caught here.","commonSituations":"Running the CLI with no internet connection or behind a corporate proxy that blocks huggingface.co; DNS misconfiguration; firewall/VPN blocking outbound HTTPS; Node versions without global fetch (Node < 18) causing 'fetch is not defined'.","solutions":["Check network connectivity (curl https://huggingface.co/api/spaces) and fix proxy/DNS/VPN issues","If behind a proxy, set HTTPS_PROXY and ensure fetch honors it (undici EnvHttpProxyAgent or Node 24+)","Upgrade to Node >= 18 so global fetch exists","Retry after a transient outage; the underlying message in the error names the exact cause"],"exampleFix":"// before (Node 16, no global fetch)\nconst resp = await fetch(url);\n// after\nconst { fetch: undiciFetch } = require('undici');\nconst resp = await undiciFetch(url, { headers: { Accept: 'application/json' } });","handlingStrategy":"try-catch","validationCode":"// connectivity pre-check\nconst ok = await fetch('https://huggingface.co/api/spaces?limit=1', { method: 'HEAD' }).then(r => r.ok).catch(() => false);\nif (!ok) console.warn('huggingface.co unreachable');","typeGuard":null,"tryCatchPattern":"try {\n  await hfSpaces(query);\n} catch (e) {\n  if (String(e.message).includes('request failed')) {\n    // network-level: backoff and retry once, or degrade gracefully\n    await new Promise(r => setTimeout(r, 2000));\n    return null; // fallback path\n  }\n  throw e;\n}","preventionTips":["Verify outbound HTTPS to huggingface.co from the deployment environment","Run Node >= 18 so global fetch is available","Configure proxy env vars (HTTPS_PROXY) if behind a corporate proxy","Add a retry with exponential backoff around CLI calls"],"tags":["network","fetch","cli","huggingface"],"backgroundTag":"fetch-network-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}