jackwener/OpenCLI · warning · EmptyResultError
crates crate
Error message
crates crate
What it means
The 'crates crate' EmptyResultError is thrown by the crates.io 'crate' subcommand when crates.io responds successfully but contains no crate metadata (body.crate missing or lacking an id), or upstream returns 404 via cratesFetch. It signals 'valid request, no data' rather than a transport failure.
Source
Thrown at clis/crates/crate.js:31
name: 'crate',
access: 'read',
description: 'Single crates.io crate metadata (latest version, downloads, license, repo)',
domain: 'crates.io',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'name', positional: true, required: true, help: 'crates.io crate name (e.g. "serde", "tokio")' },
],
columns: [
'name', 'latestVersion', 'description', 'downloads', 'recentDownloads', 'versions',
'license', 'homepage', 'documentation', 'repository', 'keywords', 'categories', 'created', 'updated', 'url',
],
func: async (args) => {
const name = requireCrateName(args.name);
const body = await cratesFetch(`${CRATES_BASE}/api/v1/crates/${encodeURIComponent(name)}`, `crates crate ${name}`);
const c = body?.crate;
if (!c || !c.id) {
throw new EmptyResultError('crates crate', `crates.io returned no metadata for "${name}".`);
}
const versions = Array.isArray(body.versions) ? body.versions : [];
const latestRow = versions.find((v) => v.num === c.newest_version)
|| versions.find((v) => v.num === c.max_stable_version)
|| versions[0]
|| {};
const keywords = Array.isArray(body.keywords)
? body.keywords.map((k) => k?.keyword || k?.id || '').filter(Boolean).join(', ')
: '';
const categories = Array.isArray(body.categories)
? body.categories.map((cat) => cat?.category || cat?.slug || '').filter(Boolean).join(', ')
: '';
return [{
name: String(c.name ?? c.id),
latestVersion: String(c.newest_version ?? c.max_stable_version ?? c.max_version ?? ''),
description: String(c.description ?? '').trim(),
downloads: c.downloads != null ? Number(c.downloads) : null,
recentDownloads: c.recent_downloads != null ? Number(c.recent_downloads) : null,View on GitHub (pinned to 49907e53dc)
Solutions
- Check the crate name spelling against crates.io in a browser.
- Search first with `crates search <term>` to find the exact crate name, then re-run `crates crate <name>`.
- Retry later if crates.io is degraded; the empty body may be transient.
- Catch EmptyResultError in your tooling and show a 'not found' message instead of crashing.
Example fix
// before
const info = await cli.crates.crate({ name: 'tokyio' });
// after
const info = await cli.crates.crate({ name: 'tokio' }); // or search first:
const hits = await cli.crates.search({ query: 'tokio' }); Defensive patterns
Strategy: try-catch
Validate before calling
if (!/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(name ?? '')) {
throw new Error(`"${name}" does not look like a crates.io crate name`);
} Type guard
function isPlausibleCrateName(v) {
return typeof v === 'string' && /^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(v.trim());
} Try / catch
try {
const info = await cli.crates.crate({ name });
} catch (e) {
if (e instanceof EmptyResultError) {
console.warn(`Crate "${name}" not found on crates.io; try 'crates search'.`);
return null;
}
throw e;
} Prevention
- Verify the name exists on crates.io before scripting around it.
- Run `crates search` first when the name is uncertain.
- Treat EmptyResultError as 'not found', not as an infrastructure failure.
- Remember yanked/removed crates may return no metadata.
When it happens
Trigger: Running `crates crate <name>` where the name does not exist on crates.io (cratesFetch maps the 404 to EmptyResultError), or crates.io returns 200 with unexpected/empty JSON so body?.crate is undefined.
Common situations: Typo in the crate name ('tokyio' instead of 'tokio'), a private/removed/yanked-only crate, a name that was never published, or a crates.io API schema change that temporarily breaks the response shape.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- crates.io returned 404 for ${url}.
- bilibili creator-stats ${bvid}
- Chess.com returned 404 for ${url}
- crates search
- Photo ID ${requestedPhotoId} was not found under subject ${s
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/673985d768dd5a97.
Report an issue: GitHub.