{"record":{"id":"5202ffbac63f7d78","repo":"usebruno/bruno","slug":"api-spec-path-is-required","errorCode":null,"errorMessage":"API spec path is required.","messagePattern":"API spec path is required\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-electron/src/ipc/mock-server/index.js","lineNumber":34,"sourceCode":"  saveMockResponse,\n  saveMockServer,\n  setMockServerResponses\n} = require('../../app/mock-server/mock-response-store');\n\nconst getResponses = (location) => listMockResponses(location);\n\nconst parseSpecContent = (content) => {\n  try {\n    return JSON.parse(content);\n  } catch {\n    const yaml = require('js-yaml');\n    return yaml.load(content);\n  }\n};\n\nconst readWorkspaceSpec = (workspacePath, specPath) => {\n  if (!specPath) {\n    throw new Error('API spec path is required.');\n  }\n\n  validateWorkspacePath(workspacePath);\n\n  const resolvedPath = path.resolve(specPath);\n  const isRegisteredSpec = getWorkspaceApiSpecs(workspacePath)\n    .some((spec) => spec.path && path.resolve(spec.path) === resolvedPath);\n\n  if (!isRegisteredSpec) {\n    throw new Error('API spec is not registered in this workspace.');\n  }\n\n  if (!fs.existsSync(resolvedPath)) {\n    throw new Error('API spec file not found.');\n  }\n\n  return parseSpecContent(fs.readFileSync(resolvedPath, 'utf8'));\n};","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/mock-server/index.js#L16-L52","documentation":"`readWorkspaceSpec` loads an OpenAPI spec for the mock server. A falsy `specPath` is rejected up front - the function cannot proceed without knowing which spec to read.","triggerScenarios":"A mock-server IPC channel calls readWorkspaceSpec with `specPath: undefined/null/''`; the renderer payload is missing the spec path field; a config migration dropped the path.","commonSituations":"Creating a mock server before selecting a spec; a workspace where the spec entry lost its path.","solutions":["Pass the spec's path (absolute, or relative to workspace) from the renderer.","Ensure the spec is registered in workspace.yml with a non-empty path.","Validate the payload shape before invoking the mock-server channel."],"exampleFix":"// before\nreadWorkspaceSpec(workspacePath, undefined);\n// after\nreadWorkspaceSpec(workspacePath, spec.path);","handlingStrategy":"validation","validationCode":"const hasSpecPath = (p) => typeof p === 'string' && p.trim().length > 0;\nif (!hasSpecPath(specPath)) throw new Error('API spec path is required.');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Require a spec selection in the mock-server UI before any action.","Validate IPC payloads against a schema at the boundary.","Ensure spec entries in workspace.yml always carry a non-empty path."],"tags":["mock-server","openapi","validation","ipc"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}