usebruno/bruno · error · Error

Invalid API spec: name and path are required

Error message

Invalid API spec: name and path are required

What it means

`addApiSpecToWorkspace` runs `isValidSpecEntry`, which (like collections) requires an object with non-empty trimmed `name` and `path` strings; otherwise it throws before the lock.

Source

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

const getWorkspaceApiSpecs = (workspacePath) => {
  const config = readWorkspaceConfig(workspacePath);
  const specs = config.specs || [];

  return specs.map((spec) => {
    const specPath = spec.path ? posixifyPath(spec.path) : spec.path;
    if (specPath && !path.isAbsolute(specPath)) {
      return {
        ...spec,
        path: path.join(workspacePath, specPath)
      };
    }
    return { ...spec, path: specPath };
  });
};

const addApiSpecToWorkspace = async (workspacePath, apiSpec) => {
  if (!isValidSpecEntry(apiSpec)) {
    throw new Error('Invalid API spec: name and path are required');
  }

  return withLock(getWorkspaceLockKey(workspacePath), async () => {
    const config = readWorkspaceConfig(workspacePath);

    if (!config.specs) {
      config.specs = [];
    }

    const normalizedSpec = {
      name: apiSpec.name.trim(),
      path: makeRelativePath(workspacePath, apiSpec.path).trim()
    };

    const existingIndex = config.specs.findIndex(
      (a) => a.name === normalizedSpec.name || (a.path && posixifyPath(a.path) === normalizedSpec.path)
    );

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Ensure `apiSpec.name` is a non-empty trimmed string.
  2. Ensure `apiSpec.path` is a non-empty trimmed path (relative is fine — it gets `makeRelativePath`-normalized).
  3. Validate both fields in the UI/controller before calling.

Example fix

// before
await addApiSpecToWorkspace(wsPath, { name: 'Petstore' });

// after
await addApiSpecToWorkspace(wsPath, { name: 'Petstore', path: '/work/ws/openapi.yml' });
Defensive patterns

Strategy: validation

Validate before calling

function isValidSpecEntry(s) {
  return !!s && typeof s === 'object'
    && typeof s.name === 'string' && s.name.trim() !== ''
    && typeof s.path === 'string' && s.path.trim() !== '';
}
if (!isValidSpecEntry(spec)) throw new Error('name and path required');

Type guard

function isSpecEntry(s: unknown): s is { name: string; path: string } {
  if (!s || typeof s !== 'object') return false;
  const o = s as any;
  return typeof o.name === 'string' && o.name.trim() !== ''
      && typeof o.path === 'string' && o.path.trim() !== '';
}

Prevention

When it happens

Trigger: Calling `addApiSpecToWorkspace(workspacePath, apiSpec)` where `apiSpec` is not an object or where `name`/`path` is missing, empty, or non-string.

Common situations: Spec-import form submitted with a blank path; programmatic caller omitted the path field; a dropped file path that resolved to empty; copy of an entry missing fields.

Related errors


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