santifer/career-ops · error · Error

4dayweek: invalid URL

Error message

4dayweek: invalid URL: ${url}

What it means

assertFourDayUrl() validates every URL used by the 4dayweek provider. It first parses the input with new URL(); if parsing fails it throws 'invalid URL'. This is a defensive gate ensuring the provider only ever fetches syntactically valid URLs before further checks on protocol and hostname.

Solutions

  1. Fix the URL string so it is a valid absolute URL including the scheme, e.g. https://4dayweek.io/jobs
  2. Check where the URL is built: log/inspect the value passed in; an empty or 'undefined' string usually means a missing config field or env var
  3. Run the string through new URL(url) in a REPL or the validationCode below to see the parse error before calling the provider
  4. Ensure any concatenation is encoded (encodeURIComponent on path segments) and free of whitespace

Example fix

// before
fetchFourDayWeek('4dayweek.io/jobs?team= platform');
// after
fetchFourDayWeek('https://4dayweek.io/jobs?team=platform');
Defensive patterns

Strategy: validation

Validate before calling

// Validate provider URLs at config-load time
function isValidHttpUrl(u) {
  try { new URL(u); return true; } catch { return false; }
}
if (!isValidHttpUrl(cfg.url)) throw new Error(`Invalid 4dayweek URL in config: ${JSON.stringify(cfg.url)}`);

Type guard

function isNonEmptyUrlString(v) {
  if (typeof v !== 'string' || v.trim() === '') return false;
  try { new URL(v); return true; } catch { return false; }
}

Try / catch

try {
  await fetchFourDayWeek(url);
} catch (e) {
  if (String(e.message).startsWith('4dayweek: invalid URL')) {
    console.error(`Config error: '${url}' is not a parseable URL — check for missing scheme, spaces, or an unset config field.`);
  } else throw e;
}

Prevention

When it happens

Trigger: Passing an empty string, undefined/null coerced to string, a URL with illegal characters (spaces, unencoded symbols), a malformed URL missing the scheme (e.g. '4dayweek.io/jobs'), or an otherwise unparseable value into the 4dayweek provider (directly via config/portals.yml or through its public API).

Common situations: A typo'd or hand-edited entry in portals.yml missing 'https://'; template interpolation producing an empty or partial URL when a company name field is missing; concatenating base + path with a stray space; reading a URL from env/config where the variable is unset so 'undefined' becomes the string.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16). Data as JSON: /api/errors/e035c37079e0b31a. Report an issue: GitHub.

Appendix: source

Thrown at providers/4dayweek.mjs:53

    try {
      const parsed = new URL(value);
      if (parsed.protocol === 'https:' && parsed.hostname === TRUSTED_HOST) {
        return { url: FEED_BASE };
      }
    } catch {
      // Ignore malformed URLs; another provider may still claim the entry.
    }
  }
  return null;
}

/** @param {string} url */
function assertFourDayUrl(url) {
  let parsed;
  try {
    parsed = new URL(url);
  } catch {
    throw new Error(`4dayweek: invalid URL: ${url}`);
  }
  if (parsed.protocol !== 'https:') throw new Error(`4dayweek: URL must use HTTPS: ${url}`);
  if (parsed.hostname !== TRUSTED_HOST) {
    throw new Error(`4dayweek: untrusted hostname "${parsed.hostname}" — must be ${TRUSTED_HOST}`);
  }
  return url;
}

/** Resolve the page cap: a positive integer `max_pages` on the entry, capped. */
function resolveMaxPages(entry) {
  const v = entry?.max_pages;
  if (Number.isInteger(v) && v > 0) return Math.min(v, MAX_PAGES_CAP);
  return DEFAULT_MAX_PAGES;
}

// NaN-safe: posted is epoch SECONDS → ms; anything non-finite yields undefined.
function toEpochMs(seconds) {
  return Number.isFinite(seconds) ? seconds * 1000 : undefined;

View on GitHub (pinned to aac998c7ed)