{"record":{"id":"25c47cfa8b818b14","repo":"santifer/career-ops","slug":"invalid-yaml-in-profile-file-customprofilepath","errorCode":null,"errorMessage":"Invalid YAML in profile file: ${customProfilePath}","messagePattern":"Invalid YAML in profile file: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/export-ats-text.mjs","lineNumber":227,"sourceCode":"}\n\n/**\n * Loads profile and CV data from file paths or default paths.\n * Fails closed if real profile configuration is missing.\n */\nexport function loadProfile(customProfilePath = null, customCvPath = null) {\n  let profileRaw = null;\n  const profileSource = customProfilePath || process.env.CAREER_OPS_PROFILE || 'config/profile.yml';\n\n  if (customProfilePath) {\n    if (!existsSync(customProfilePath)) {\n      throw new Error(`Profile configuration file not found at: ${customProfilePath}`);\n    }\n    try {\n      const content = readFileSync(customProfilePath, 'utf8');\n      profileRaw = yaml.load(content);\n      if (!profileRaw || typeof profileRaw !== 'object') {\n        throw new Error(`Invalid YAML in profile file: ${customProfilePath}`);\n      }\n    } catch (err) {\n      throw new Error(`Failed to read profile file at ${customProfilePath}: ${err.message}`);\n    }\n  } else {\n    if (!existsSync(profileSource)) {\n      throw new Error('config/profile.yml not found: fill it in first');\n    }\n    try {\n      const content = readFileSync(profileSource, 'utf8');\n      profileRaw = yaml.load(content);\n      if (!profileRaw || typeof profileRaw !== 'object') {\n        throw new Error('config/profile.yml is empty or invalid YAML: fill it in first');\n      }\n    } catch (err) {\n      throw new Error(`Failed to read profile file at ${profileSource}: ${err.message}`);\n    }\n  }","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/santifer/career-ops/blob/1696bec4d021768e7359f9aad6b329cba883da20/scripts/export-ats-text.mjs#L209-L245","documentation":"Inside loadProfile, after reading the explicitly provided profile file, the parsed YAML must yield a non-null object; null, a scalar, or an array-equivalent fails this check and throws. Note this thrown Error is immediately caught by the surrounding catch and rethrown as error 305, so in practice callers see the wrapper message containing this text plus the original reason.","triggerScenarios":"yaml.load on the custom profile returns null/undefined/primitive: an empty file, a file containing only comments, a document that is just a scalar (e.g. 'name only'), or invalid YAML that js-yaml happens to parse into null (e.g. '---' alone).","commonSituations":"Saving an empty profile.yml placeholder; a merge conflict marker file; editor wrote only comments; truncation during copy; using a .yml template never filled in; wrong file passed (e.g. a lockfile or TSV).","solutions":["Open the file and add valid top-level YAML mapping content (name:, email:, etc.) — an empty or comment-only file parses to null.","Validate before calling: `const d = yaml.load(readFileSync(p,'utf8')); if (!d || typeof d !== 'object') throw ...` to get a clearer standalone error.","Confirm you passed the intended profile file, not an empty template or unrelated YAML."],"exampleFix":"// before (empty profile.yml)\n# TODO: fill in\n\n// after\nname: Ada Lovelace\nemail: ada@example.com\nlocation: Taipei","handlingStrategy":"type-guard","validationCode":"import { readFileSync } from 'node:fs';\nimport yaml from 'js-yaml';\nconst doc = yaml.load(readFileSync(customProfilePath, 'utf8'));\nif (doc === null || typeof doc !== 'object') {\n  throw new Error(`${customProfilePath} is empty or not a YAML mapping — fill it in`);\n}","typeGuard":"function isYamlMapping(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length > 0;\n}","tryCatchPattern":"try {\n  const profile = loadProfile(customProfilePath);\n} catch (e) {\n  if (e.message.includes('Failed to read profile file') && e.message.includes('Invalid YAML')) {\n    console.error('Profile parsed to null/primitive — file is empty or comment-only. Fill in profile values.');\n  } else throw e;\n}","preventionTips":["Never ship an empty or comments-only profile.yml; always include at least one real key: value pair.","Run your YAML through a parser check after editing (CI or editor plugin).","Copy from config/profile.example.yml and replace values rather than starting from a blank file."],"tags":["yaml","configuration","parse-error","empty-file"],"backgroundTag":"invalid-yaml-config","analyzedSha":"1696bec4d021768e7359f9aad6b329cba883da20","analyzedAt":"2026-09-01T19:19:23.111Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}