santifer/career-ops · error · Error

Invalid YAML in profile file

Error message

Invalid YAML in profile file: ${customProfilePath}

What it means

Thrown by loadProfile() when the custom profile YAML parses (or the file reads) but yaml.load() returns null/undefined or a non-object — i.e. the file is empty or contains a scalar/array instead of a mapping. Note this inner throw is immediately caught by the surrounding catch and re-wrapped as error 462 ('Failed to read profile file at ...'), so you will normally see the wrapped message with this text as its cause.

Solutions

  1. Open the file and ensure it contains a valid YAML mapping (key: value pairs), not empty content or a bare scalar.
  2. Re-copy the template: cp config/profile.example.yml <your-profile-path> and edit it.
  3. Validate the YAML independently (e.g. node -e "console.log(require('yaml').parse(require('fs').readFileSync(p,'utf8')))" ) to see what it parses to.
  4. Check for encoding issues (BOM/UTF-16) that can make the parser return unexpected values.

Example fix

// before: profile.yml contains only '# TODO fill in' (parses to null)
// after: give it a mapping
name: Jane Doe
email: jane@example.com
target_role: Senior Backend Engineer
Defensive patterns

Strategy: validation

Validate before calling

const parsed = yaml.parse(readFileSync(profilePath, 'utf8'));
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
  throw new Error(`${profilePath} must contain a YAML mapping, not be empty or a scalar`);
}

Type guard

const isYamlMapping = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);

Prevention

When it happens

Trigger: loadProfile(customProfilePath) where the file exists but yaml.load(content) yields a falsy or non-object value: empty file, file containing only comments, a bare string/number, or 'null'.

Common situations: Profile file created but never filled in; an editor/save glitch truncated it to zero bytes; someone wrote JSON-in-YAML that serializes to a scalar; a placeholder file with only comments.

Related errors


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

Appendix: source

Thrown at scripts/export-ats-text.mjs:227

}

/**
 * Loads profile and CV data from file paths or default paths.
 * Fails closed if real profile configuration is missing.
 */
export function loadProfile(customProfilePath = null, customCvPath = null) {
  let profileRaw = null;
  const profileSource = customProfilePath || process.env.CAREER_OPS_PROFILE || 'config/profile.yml';

  if (customProfilePath) {
    if (!existsSync(customProfilePath)) {
      throw new Error(`Profile configuration file not found at: ${customProfilePath}`);
    }
    try {
      const content = readFileSync(customProfilePath, 'utf8');
      profileRaw = yaml.load(content);
      if (!profileRaw || typeof profileRaw !== 'object') {
        throw new Error(`Invalid YAML in profile file: ${customProfilePath}`);
      }
    } catch (err) {
      throw new Error(`Failed to read profile file at ${customProfilePath}: ${err.message}`);
    }
  } else {
    if (!existsSync(profileSource)) {
      throw new Error('config/profile.yml not found: fill it in first');
    }
    try {
      const content = readFileSync(profileSource, 'utf8');
      profileRaw = yaml.load(content);
      if (!profileRaw || typeof profileRaw !== 'object') {
        throw new Error('config/profile.yml is empty or invalid YAML: fill it in first');
      }
    } catch (err) {
      throw new Error(`Failed to read profile file at ${profileSource}: ${err.message}`);
    }
  }

View on GitHub (pinned to aac998c7ed)