{"record":{"id":"1dca71c83bd3a0c1","repo":"usebruno/bruno","slug":"invalid-workspace-workspace-yml-is-malformed","errorCode":null,"errorMessage":"Invalid workspace: workspace.yml is malformed","messagePattern":"Invalid workspace: workspace\\.yml is malformed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-electron/src/utils/workspace-config.js","lineNumber":230,"sourceCode":"    specs,\n    // Distinct array (not an alias of `specs`) so a later in-place mutation of\n    // one field can't silently change the other.\n    apiSpecs: [...specs]\n  };\n};\n\nconst readWorkspaceConfig = (workspacePath) => {\n  const workspaceFilePath = path.join(workspacePath, 'workspace.yml');\n\n  if (!fs.existsSync(workspaceFilePath)) {\n    throw new Error('Invalid workspace: workspace.yml not found');\n  }\n\n  const yamlContent = fs.readFileSync(workspaceFilePath, 'utf8');\n  const workspaceConfig = yaml.load(yamlContent);\n\n  if (!workspaceConfig || typeof workspaceConfig !== 'object') {\n    throw new Error('Invalid workspace: workspace.yml is malformed');\n  }\n\n  return normalizeWorkspaceConfig(workspaceConfig);\n};\n\nconst generateYamlContent = (config) => {\n  const yamlLines = [];\n  const workspaceName = config.info?.name || config.name || 'Untitled Workspace';\n  const workspaceType = config.info?.type || config.type || WORKSPACE_TYPE;\n\n  yamlLines.push(`opencollection: ${config.opencollection || OPENCOLLECTION_VERSION}`);\n  yamlLines.push('info:');\n  yamlLines.push(`  name: ${quoteYamlValue(workspaceName)}`);\n  yamlLines.push(`  type: ${workspaceType}`);\n  yamlLines.push('');\n\n  const collections = sanitizeCollections(config.collections);\n  if (collections.length > 0) {","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/utils/workspace-config.js#L212-L248","documentation":"`readWorkspaceConfig` reads and `yaml.load()`s `workspace.yml`; if the result is falsy or not an object (empty file, plain scalar, YAML null) it throws. The file exists but does not deserialize into a config map.","triggerScenarios":"`workspace.yml` parses to `null`, a string, a number, or an array; common with an empty file, a single scalar line, or a document that is only comments.","commonSituations":"Truncated/corrupted write; editor saved an empty file; a manual edit left only a scalar; sync conflict produced an empty file; the file contains only a YAML comment.","solutions":["Restore `workspace.yml` from version control or backup.","Regenerate it via `writeWorkspaceConfig(path, createWorkspaceConfig(name))`.","Open the file and confirm it has the `opencollection:`/`info:`/`collections:` structure.","Prevent external tools from truncating it during sync."],"exampleFix":"// before: workspace.yml contains only\n//   # my notes\n\n// after: regenerate\nawait writeWorkspaceConfig(wsPath, createWorkspaceConfig('MyWorkspace'));","handlingStrategy":"validation","validationCode":"const yaml = require('js-yaml');\nfunction parseWorkspaceYaml(raw) {\n  const cfg = yaml.load(raw);\n  if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg)) {\n    throw new Error('workspace.yml is empty or not a mapping');\n  }\n  return cfg;\n}","typeGuard":"function isPlainObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v);\n}","tryCatchPattern":null,"preventionTips":["Never save an empty workspace.yml.","Lint YAML on save in editors to catch truncation."],"tags":["workspace","yaml","config","parsing"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}