santifer/career-ops · error

careerviet: invalid URL

Error message

careerviet: invalid URL: ${url}

What it means

The CareerViet provider's assertCareerVietUrl guard throws this when the URL string cannot be parsed by new URL(). Every CareerViet request URL passes through this SSRF guard before fetching; a value that is not a syntactically valid absolute URL is rejected before any network I/O.

Solutions

  1. Correct the URL in the careerviet portals entry to the full absolute form 'https://www.capabilities'... i.e. 'https://www.careerviet.vn/...'.
  2. Reproduce the SyntaxError locally with `new URL(value)` to see exactly which character breaks parsing.
  3. Trim whitespace/control characters and confirm the scheme separator is '://'.
  4. If the URL is composed in code, log the intermediate parts to find the empty/undefined segment.

Example fix

// before
const url = `https://${undefined}/viec-lam`;
// after
const base = 'https://www.careerviet.vn';
const url = `${base}/viec-lam`;
Defensive patterns

Strategy: validation

Validate before calling

function isValidUrl(u) {
  try { new URL(u); return true; } catch { return false; }
}
if (!isValidUrl(entry.careers_url)) throw new Error(`careerviet entry URL unparseable: ${entry.careers_url}`);

Type guard

function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; }

Try / catch

try {
  await provider.fetch(entry, ctx);
} catch (err) {
  if (String(err.message).startsWith('careerviet: invalid URL')) {
    console.warn(`Skipping careerviet entry: malformed URL — fix portals.yml`);
    return null;
  }
  throw err;
}

Prevention

When it happens

Trigger: A request URL for careerviet_vn composed from a malformed config value or a broken template interpolation: missing scheme, 'https:/careerviet.vn' (single slash), embedded whitespace, or an empty origin segment reaching assertCareerVietUrl.

Common situations: Hand-edited portals.yml entry with a typo in the URL; environment-variable or templating substitution that came out empty; copying a URL with an invisible trailing character from a document.

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/9a43fd1b259276a1. Report an issue: GitHub.

Appendix: source

Thrown at providers/careerviet.mjs:106

 * The "Cập nhật" (updated) date sits in its own <li>, sibling to "Hạn nộp"
 * (deadline) inside the same .time block — the label text is what tells them
 * apart; both wrap their <time> the same way.
 */
const UPDATED_DATE_RE = /Cập nhật(?:<!--[\s\S]*?-->)?\s*:?\s*(?:<\/span>)?\s*<time>([\d/-]+)<\/time>/i;

/** @param {any} ctx @param {number} ms */
function sleep(ctx, ms) {
  if (typeof ctx?.sleep === 'function') return ctx.sleep(ms);
  return new Promise((r) => setTimeout(r, ms));
}

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

/**
 * Collapse a markup fragment to its visible text.
 * @param {string} fragment
 * @returns {string}
 */
export function visibleText(fragment) {
  return decodeEntities(
    String(fragment ?? '')
      .replace(/<!--[\s\S]*?-->/g, ' ')
      .replace(/<[^>]+>/g, ' '),

View on GitHub (pinned to aac998c7ed)