{"record":{"id":"4d19f7d5fd1db81f","repo":"jackwener/OpenCLI","slug":"hf-datasets","errorCode":null,"errorMessage":"hf datasets","messagePattern":"hf datasets","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"error","filePath":"clis/hf/datasets.js","lineNumber":69,"sourceCode":"                    'Accept': 'application/json',\n                    'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',\n                },\n            });\n        } catch (error) {\n            throw new CommandExecutionError(`hf datasets request failed: ${error?.message || error}`);\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`hf datasets failed: HTTP ${resp.status}`);\n        }\n        let data;\n        try {\n            data = await resp.json();\n        } catch (error) {\n            throw new CommandExecutionError(`hf datasets returned malformed JSON: ${error?.message || error}`);\n        }\n        const list = Array.isArray(data) ? data : [];\n        if (list.length === 0) {\n            throw new EmptyResultError('hf datasets', 'No matching datasets on huggingface.co.');\n        }\n        return list.slice(0, limit).map((d, i) => {\n            const id = d.id || '';\n            const slashIdx = id.indexOf('/');\n            const author = slashIdx > 0 ? id.slice(0, slashIdx) : '';\n            const tags = Array.isArray(d.tags) ? d.tags.filter(t => !t.startsWith('license:')).slice(0, 10).join(', ') : '';\n            return {\n                rank: i + 1,\n                id,\n                author,\n                downloads: d.downloads ?? 0,\n                likes: d.likes ?? 0,\n                tags,\n                lastModified: d.lastModified ? String(d.lastModified).slice(0, 10) : '',\n                url: id ? `https://huggingface.co/datasets/${id}` : '',\n            };\n        });\n    },","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/datasets.js#L51-L87","documentation":"EmptyResultError('hf datasets', 'No matching datasets on huggingface.co.') is thrown by the `hf datasets` command when the Hugging Face /api/datasets endpoint returns a successful HTTP response whose parsed body is an empty array (or a non-array body). The library uses it to distinguish 'the API worked but returned nothing' from network or protocol failures so callers can handle empty results explicitly.","triggerScenarios":"Running `hf datasets` (or with --search) when the fetch succeeds (resp.ok) but the parsed JSON array is empty — e.g. a search string matches no dataset, the search term is misspelled or too specific, or the API returns an empty/non-array payload for the given sort/filters.","commonSituations":"Typo in --search (e.g. 'llamaa' instead of 'llama'); querying an owner prefix like 'someorg/' that has no datasets; a sort/filter combination with zero matching datasets; Hugging Face returning an empty page during API incidents or partial outages.","solutions":["Re-run with a broader or corrected --search term (check spelling and owner prefix).","Remove --search filters to confirm the API returns data at all.","Change the --sort key (e.g. from 'trending' to 'downloads') in case one ordering yields no rows.","If it persists with no filters, check https://huggingface.co status — the API may be returning empty responses."],"exampleFix":"// before\nopencli hf datasets --search 'my-typo-dataset-name'\n// after\nopencli hf datasets --search 'squad'","handlingStrategy":"try-catch","validationCode":"// Pre-check: does the search term exist at all?\nconst r = await fetch('https://huggingface.co/api/datasets?search=' + encodeURIComponent(term) + '&limit=1');\nconst rows = await r.json();\nif (!Array.isArray(rows) || rows.length === 0) console.warn(`No datasets match \"${term}\" — widen the search before calling hf datasets`);","typeGuard":"const isNonEmptyArray = (v) => Array.isArray(v) && v.length > 0;","tryCatchPattern":"try {\n  await run('hf datasets --search ' + term);\n} catch (e) {\n  if (e.name === 'EmptyResultError') {\n    console.warn('No matching datasets; retrying without filters');\n    await run('hf datasets');\n  } else throw e;\n}","preventionTips":["Spot-check search terms and owner prefixes on huggingface.co/datasets before scripting.","Retry once with filters removed before treating it as a hard failure.","Prefer broad terms ('squad') over exact repo names in --search.","Watch HF status for incidents that can return empty pages."],"tags":["empty-result","api","huggingface","network"],"backgroundTag":"empty-api-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}