usebruno/bruno · error · Error

Invalid workspace: workspace.yml is malformed

Error message

Invalid workspace: workspace.yml is malformed

What it means

`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.

Source

Thrown at packages/bruno-electron/src/utils/workspace-config.js:230

    specs,
    // Distinct array (not an alias of `specs`) so a later in-place mutation of
    // one field can't silently change the other.
    apiSpecs: [...specs]
  };
};

const readWorkspaceConfig = (workspacePath) => {
  const workspaceFilePath = path.join(workspacePath, 'workspace.yml');

  if (!fs.existsSync(workspaceFilePath)) {
    throw new Error('Invalid workspace: workspace.yml not found');
  }

  const yamlContent = fs.readFileSync(workspaceFilePath, 'utf8');
  const workspaceConfig = yaml.load(yamlContent);

  if (!workspaceConfig || typeof workspaceConfig !== 'object') {
    throw new Error('Invalid workspace: workspace.yml is malformed');
  }

  return normalizeWorkspaceConfig(workspaceConfig);
};

const generateYamlContent = (config) => {
  const yamlLines = [];
  const workspaceName = config.info?.name || config.name || 'Untitled Workspace';
  const workspaceType = config.info?.type || config.type || WORKSPACE_TYPE;

  yamlLines.push(`opencollection: ${config.opencollection || OPENCOLLECTION_VERSION}`);
  yamlLines.push('info:');
  yamlLines.push(`  name: ${quoteYamlValue(workspaceName)}`);
  yamlLines.push(`  type: ${workspaceType}`);
  yamlLines.push('');

  const collections = sanitizeCollections(config.collections);
  if (collections.length > 0) {

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Restore `workspace.yml` from version control or backup.
  2. Regenerate it via `writeWorkspaceConfig(path, createWorkspaceConfig(name))`.
  3. Open the file and confirm it has the `opencollection:`/`info:`/`collections:` structure.
  4. Prevent external tools from truncating it during sync.

Example fix

// before: workspace.yml contains only
//   # my notes

// after: regenerate
await writeWorkspaceConfig(wsPath, createWorkspaceConfig('MyWorkspace'));
Defensive patterns

Strategy: validation

Validate before calling

const yaml = require('js-yaml');
function parseWorkspaceYaml(raw) {
  const cfg = yaml.load(raw);
  if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg)) {
    throw new Error('workspace.yml is empty or not a mapping');
  }
  return cfg;
}

Type guard

function isPlainObject(v: unknown): v is Record<string, unknown> {
  return typeof v === 'object' && v !== null && !Array.isArray(v);
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13). Data as JSON: /api/errors/1dca71c83bd3a0c1. Report an issue: GitHub.