jackwener/OpenCLI · error · ArgumentError
lobsters domain "${value}" is not a valid hostname
Error message
lobsters domain "${value}" is not a valid hostname What it means
Thrown by requireDomain() when the supplied value fails DOMAIN_PATTERN, which requires at least two dot-separated labels of alphanumeric/hyphen characters with no spaces, scheme, path, or trailing hyphens. The library rejects anything that is not a plain hostname before making a request.
Source
Thrown at clis/lobsters/domain.js:18
// lobsters domain — list Lobste.rs stories submitted from a specific domain.
//
// Hits the public `https://lobste.rs/domains/<domain>.json` endpoint
// (returns the same per-story shape used by `lobsters tag` / `lobsters
// hot`). Lets agents ask "what did Lobsters surface from github.com /
// blog.cloudflare.com / arxiv.org lately?".
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
const DOMAIN_PATTERN = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$/i;
function requireDomain(value) {
const s = String(value ?? '').trim().toLowerCase();
if (!s) {
throw new ArgumentError('lobsters domain is required (e.g. "github.com" or "arxiv.org")');
}
if (!DOMAIN_PATTERN.test(s)) {
throw new ArgumentError(`lobsters domain "${value}" is not a valid hostname`);
}
return s;
}
function requireBoundedInt(value, defaultValue, maxValue) {
const raw = value ?? defaultValue;
const n = typeof raw === 'number' ? raw : Number(raw);
if (!Number.isInteger(n) || n <= 0) {
throw new ArgumentError('lobsters limit must be a positive integer');
}
if (n > maxValue) {
throw new ArgumentError(`lobsters limit must be <= ${maxValue}`);
}
return n;
}
cli({
site: 'lobsters',View on GitHub (pinned to 49907e53dc)
Solutions
- Strip scheme, path, and query, leaving only the hostname: new URL(input).hostname
- Ensure the value has at least two dot-separated labels, e.g. 'arxiv.org' not 'arxiv'
- Remove surrounding whitespace or stray characters (quotes, trailing slash)
- If a bare single label like 'localhost' is intended, note this API does not accept it
Example fix
// before
await cli.domain('https://github.com/trending');
// after
await cli.domain(new URL('https://github.com/trending').hostname); // 'github.com' Defensive patterns
Strategy: validation
Validate before calling
const DOMAIN_PATTERN = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$/i;
function isValidDomain(v) {
const s = String(v ?? '').trim().toLowerCase();
return DOMAIN_PATTERN.test(s);
}
if (!isValidDomain(input)) input = new URL(input).hostname; Type guard
function isBareHostname(v) {
return typeof v === 'string' && /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$/i.test(v.trim());
} Try / catch
try {
await cli.domain(input);
} catch (err) {
if (err instanceof ArgumentError && /not a valid hostname/.test(err.message)) {
input = new URL(input.startsWith('http') ? input : `https://${input}`).hostname;
return cli.domain(input);
}
throw err;
} Prevention
- Normalize full URLs to hostname with new URL(input).hostname before passing
- Trim whitespace and strip quotes/slashes from user input
- Validate with the same hostname regex in your own form/CLI parsing layer
When it happens
Trigger: Passing 'https://github.com', 'github.com/', 'github .com', '-github.com', 'localhost', 'github', or a full URL into domain()/requireDomain().
Common situations: Users paste a full URL copied from the browser instead of the bare domain; trailing slash or path included; subdomain-only shorthand like 'en.wikipedia' lacking a TLD; uppercase is fine (pattern is case-insensitive) but spaces and schemes are not.
Related errors
- coingecko derivatives limit must be a positive integer
- --from and --to must differ (got ${fromCity})
- ${label} must be a positive integer
- ${label} must be an integer >= ${min}
- Invalid HN item id: ${args.id}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/db43e21f9dd2a6c4.
Report an issue: GitHub.