santifer/career-ops · error

careerviet: URL must use HTTPS

Error message

careerviet: URL must use HTTPS: ${url}

What it means

assertCareerVietUrl throws this when the URL parses but its protocol is not 'https:'. The CareerViet provider fetches only over TLS, both for transport security and as part of the SSRF guard chain; http:// or any other scheme is rejected before the request.

Solutions

  1. Change the scheme to https:// in the portals entry or composing code.
  2. Let the provider own the base URL — config should carry the site path, not an overridable scheme.
  3. Update http:// test fixtures to https:// so they clear the guard.

Example fix

// before
const url = 'http://www.careerviet.vn/viec-lam';
// after
const url = 'https://www.careerviet.vn/viec-lam';
Defensive patterns

Strategy: validation

Validate before calling

function isHttpsUrl(u) {
  try { return new URL(u).protocol === 'https:'; } catch { return false; }
}
if (!isHttpsUrl(entry.careers_url)) throw new Error(`careerviet entry must use https: ${entry.careers_url}`);

Type guard

function isHttpsProtocol(u) { try { return new URL(u).protocol === 'https:'; } catch { return false; } }

Try / catch

try {
  await provider.fetch(entry, ctx);
} catch (err) {
  if (String(err.message).startsWith('careerviet: URL must use HTTPS')) {
    const fixed = entry.careers_url.replace(/^http:/, 'https:');
    console.warn(`Retrying ${entry.name} with https`);
    return provider.fetch({ ...entry, careers_url: fixed }, ctx);
  }
  throw err;
}

Prevention

When it happens

Trigger: A careerviet entry configured with 'http://www.careerviet.vn/...' or an internally composed URL whose scheme was mistyped or downgraded reaches assertCareerVietUrl.

Common situations: Writing http:// out of habit in local config; a migration/rewrite that dropped the 's'; test fixtures using http endpoints run through the production guard.

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/45dba1f1495445e1. Report an issue: GitHub.

Appendix: source

Thrown at providers/careerviet.mjs:108

 * 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, ' '),
  )
    .replace(/\s+/g, ' ')

View on GitHub (pinned to aac998c7ed)