lissy93/web-check · error · Error

No target provided

Error message

No target provided

What it means

Thrown by parseTarget in api/_common/parse-target.js when the input argument is falsy (undefined, null, empty string). This is the entry-point guard for normalising a user-supplied target before DNS resolution and URL parsing. It exists so downstream code never operates on an absent target.

Source

Thrown at api/_common/parse-target.js:12

// Wrap bare IPv6 in brackets for URL parsing (2+ colons = IPv6)
export const bracketIPv6 = (str) => {
  const bare = str.replace(/^https?:\/\//i, '');
  const host = bare.split('/')[0];
  if (!host.startsWith('[') && (host.match(/:/g) || []).length >= 2)
    return str.replace(host, `[${host}]`);
  return str;
};

// Normalise a user-supplied target, stripping :port for DNS lookups
export const parseTarget = (input) => {
  if (!input) throw new Error('No target provided');
  let normalised = /^https?:\/\//i.test(input) ? input : `https://${input}`;
  normalised = bracketIPv6(normalised);
  let u;
  try {
    u = new URL(normalised);
  } catch {
    throw new Error(`Invalid URL: ${input}`);
  }
  return {
    hostname: u.hostname.replace(/^\[|]$/g, ''),
    port: u.port || null,
    protocol: u.protocol,
    pathname: u.pathname || '/',
    href: u.href,
  };
};

export default parseTarget;

View on GitHub (pinned to af1a97759f)

Solutions

  1. Supply a non-empty target string (hostname or URL) to parseTarget
  2. Check the caller that extracts the query parameter — it is likely reading the wrong param name or from the wrong object (queryStringParameters vs query)
  3. Add an early validation in your own handler before delegating to this API

Example fix

// before
const t = await parseTarget(query.target); // query.target is undefined

// after
const raw = query.target;
if (!raw) throw new Error('Missing "target" query parameter');
const t = await parseTarget(raw);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof target !== 'string' || target.trim() === '') {
  throw new Error('Missing "target" query parameter');
}
const parsed = parseTarget(target.trim());

Type guard

/** @param {unknown} v */
const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;

Try / catch

try {
  const t = parseTarget(input);
} catch (e) {
  if (e.message === 'No target provided') return badRequest('target is required');
  throw e;
}

Prevention

When it happens

Trigger: Calling parseTarget(undefined), parseTarget(null), parseTarget(''), or invoking an API endpoint backed by it without the required target query parameter.

Common situations: Missing ?url= (or equivalent) query parameter in the HTTP request; a caller passing a destructured variable that was never set; environment-specific configs where the param name differs between local dev and deployment.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of lissy93/web-check@af1a97759f (2026-08-27). Data as JSON: /api/errors/5ae4706c0134f364. Report an issue: GitHub.