{"record":{"id":"e035c37079e0b31a","repo":"santifer/career-ops","slug":"4dayweek-invalid-url-url","errorCode":null,"errorMessage":"4dayweek: invalid URL: ${url}","messagePattern":"4dayweek: invalid URL: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"providers/4dayweek.mjs","lineNumber":53,"sourceCode":"    try {\n      const parsed = new URL(value);\n      if (parsed.protocol === 'https:' && parsed.hostname === TRUSTED_HOST) {\n        return { url: FEED_BASE };\n      }\n    } catch {\n      // Ignore malformed URLs; another provider may still claim the entry.\n    }\n  }\n  return null;\n}\n\n/** @param {string} url */\nfunction assertFourDayUrl(url) {\n  let parsed;\n  try {\n    parsed = new URL(url);\n  } catch {\n    throw new Error(`4dayweek: invalid URL: ${url}`);\n  }\n  if (parsed.protocol !== 'https:') throw new Error(`4dayweek: URL must use HTTPS: ${url}`);\n  if (parsed.hostname !== TRUSTED_HOST) {\n    throw new Error(`4dayweek: untrusted hostname \"${parsed.hostname}\" — must be ${TRUSTED_HOST}`);\n  }\n  return url;\n}\n\n/** Resolve the page cap: a positive integer `max_pages` on the entry, capped. */\nfunction resolveMaxPages(entry) {\n  const v = entry?.max_pages;\n  if (Number.isInteger(v) && v > 0) return Math.min(v, MAX_PAGES_CAP);\n  return DEFAULT_MAX_PAGES;\n}\n\n// NaN-safe: posted is epoch SECONDS → ms; anything non-finite yields undefined.\nfunction toEpochMs(seconds) {\n  return Number.isFinite(seconds) ? seconds * 1000 : undefined;","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/providers/4dayweek.mjs#L35-L71","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Fix the URL string so it is a valid absolute URL including the scheme, e.g. https://4dayweek.io/jobs","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","Run the string through new URL(url) in a REPL or the validationCode below to see the parse error before calling the provider","Ensure any concatenation is encoded (encodeURIComponent on path segments) and free of whitespace"],"exampleFix":"// before\nfetchFourDayWeek('4dayweek.io/jobs?team= platform');\n// after\nfetchFourDayWeek('https://4dayweek.io/jobs?team=platform');","handlingStrategy":"validation","validationCode":"// Validate provider URLs at config-load time\nfunction isValidHttpUrl(u) {\n  try { new URL(u); return true; } catch { return false; }\n}\nif (!isValidHttpUrl(cfg.url)) throw new Error(`Invalid 4dayweek URL in config: ${JSON.stringify(cfg.url)}`);","typeGuard":"function isNonEmptyUrlString(v) {\n  if (typeof v !== 'string' || v.trim() === '') return false;\n  try { new URL(v); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  await fetchFourDayWeek(url);\n} catch (e) {\n  if (String(e.message).startsWith('4dayweek: invalid URL')) {\n    console.error(`Config error: '${url}' is not a parseable URL — check for missing scheme, spaces, or an unset config field.`);\n  } else throw e;\n}","preventionTips":["Always store full absolute URLs including https:// in portals.yml and provider config","Assert every configured URL parses with new URL() at startup, failing fast with the offending key","Beware template interpolation: log the final URL when a company/role field may be empty","Trim and URL-encode user- or scrape-derived strings before passing them to the provider"],"tags":["validation","url","provider"],"backgroundTag":"invalid-url-format","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}