jackwener/OpenCLI · warning · CliError
NOT_FOUND
NOT_FOUND
Error message
No articles found
What it means
CliError with code NOT_FOUND thrown by `opencli wikipedia search` when list=search returns an empty results array — no articles matched the search term on that language's Wikipedia. This is an expected outcome of a bad/over-specific query, not a crash.
Source
Thrown at clis/wikipedia/search.js:24
name: 'search',
access: 'read',
description: 'Search Wikipedia articles',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'query', positional: true, required: true, help: 'Search keyword' },
{ name: 'limit', type: 'int', default: 10, help: 'Max results' },
{ name: 'lang', default: 'en', help: 'Language code (e.g. en, zh, ja)' },
],
columns: ['title', 'snippet', 'url'],
func: async (args) => {
const limit = Math.max(1, Math.min(Number(args.limit), 50));
const lang = args.lang || 'en';
const q = encodeURIComponent(args.query);
const data = (await wikiFetch(lang, `/w/api.php?action=query&list=search&srsearch=${q}&srlimit=${limit}&format=json&utf8=1`));
const results = data?.query?.search;
if (!results?.length)
throw new CliError('NOT_FOUND', 'No articles found', 'Try a different keyword');
return results.map((r) => ({
title: r.title,
snippet: r.snippet.replace(/<[^>]+>/g, '').slice(0, 120),
url: `https://${lang}.wikipedia.org/wiki/${encodeURIComponent(r.title.replace(/ /g, '_'))}`,
}));
},
});
View on GitHub (pinned to 49907e53dc)
Solutions
- Simplify the query to one or two broad keywords
- Verify --lang matches the language your query is written in
- Use wildcards or partial words (MediaWiki search supports prefix matching, e.g. javasc*)
- Check spelling
Example fix
// before opencli wikipedia search "the complete history of the transistor radio in japan" --lang zh // after opencli wikipedia search "transistor" --lang en
Defensive patterns
Strategy: try-catch
Validate before calling
if (!query.trim()) throw new Error('search query required');
if (Number(limit) > 50) limit = 50; Type guard
function hasSearchResults(d) {
return Array.isArray(d?.query?.search) && d.query.search.length > 0;
} Try / catch
try {
const rows = await run('wikipedia search', [query, '--lang', lang]);
} catch (e) {
if (e.code === 'NOT_FOUND') {
console.log(`No hits for "${query}" on ${lang}.wikipedia.org; try broader keywords or a matching language`);
} else throw e;
} Prevention
- Use short, broad keyword queries
- Match query language to the --lang edition
- Check spelling before searching
When it happens
Trigger: `opencli wikipedia search <query> --lang <lang>` where data.query.search is [] — the full-text search index has no matches for srsearch.
Common situations: Misspelled keywords, queries in a language different from the wiki edition, extremely specific multi-word phrases, searching for non-encyclopedic terms.
Understand the failure class
Background: NOT_FOUND error code: why tRPC, Harbor, Nacos and other libraries return 404 "not found" errors for resources that may still exist — this error's family across 11 libraries.
Related errors
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/9a664e1f02174a08.
Report an issue: GitHub.