paperclipai/paperclip · error · Error

Hostname is required

Error message

Hostname is required

What it means

Thrown by normalizeHostnameInput when the trimmed input is empty. The function is the canonical hostname normalizer used by hostname/allowed-hosts configuration; it trims then rejects zero-length input before attempting URL parsing. parseHostnameCsv calls it per comma-separated part, so a stray comma or blank segment in a CSV also triggers this.

Source

Thrown at cli/src/config/hostnames.ts:4

export function normalizeHostnameInput(raw: string): string {
  const input = raw.trim();
  if (!input) {
    throw new Error("Hostname is required");
  }

  try {
    const url = input.includes("://") ? new URL(input) : new URL(`http://${input}`);
    const hostname = url.hostname.trim().toLowerCase();
    if (!hostname) throw new Error("Hostname is required");
    return hostname;
  } catch {
    throw new Error(`Invalid hostname: ${raw}`);
  }
}

export function parseHostnameCsv(raw: string): string[] {
  if (!raw.trim()) return [];
  const unique = new Set<string>();
  for (const part of raw.split(",")) {
    const hostname = normalizeHostnameInput(part);
    unique.add(hostname);

View on GitHub (pinned to 67001ec6eb)

Solutions

  1. Provide a non-empty hostname string after trimming.
  2. If using parseHostnameCsv, sanitize the CSV to remove empty segments first (filter(Boolean)).
  3. Guard callers to skip hostname normalization when the input is meant to be optional.

Example fix

// before
const h = normalizeHostnameInput(process.env.HOST ?? '');
// after
const raw = (process.env.HOST ?? '').trim();
if (!raw) throw new Error('HOST env var is required');
const h = normalizeHostnameInput(raw);
Defensive patterns

Strategy: validation

Validate before calling

function requireHostname(raw: string): string {
  const trimmed = raw.trim();
  if (!trimmed) {
    throw new Error("Hostname is required");
  }
  return trimmed;
}

// for CSV inputs, drop empty segments before normalizing:
function sanitizeHostnameCsv(raw: string): string[] {
  return Array.from(new Set(
    raw.split(",").map((p) => p.trim()).filter(Boolean),
  ));
}

Type guard

function isNonEmptyHostname(raw: string): boolean {
  return raw.trim().length > 0;
}

Prevention

When it happens

Trigger: Calling normalizeHostnameInput(''), normalizeHostnameInput(' '), or parseHostnameCsv with a CSV containing an empty segment like 'host1,,host2'.

Common situations: A developer passes an empty string from an env var (e.g. PAPERCLIP_HOSTNAME unset yields ''). Or a config form submits a blank hostname field. Or a CSV with trailing/leading/double commas.

Related errors


AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12). Data as JSON: /api/errors/dc7cf1d05bef1c7f. Report an issue: GitHub.