{"record":{"id":"9e7b6882e98d0856","repo":"usebruno/bruno","slug":"invalid-scope-type-scopetype","errorCode":null,"errorMessage":"Invalid scope type: ${scopeType}","messagePattern":"Invalid scope type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-electron/src/ipc/collection.js","lineNumber":679,"sourceCode":"      }\n\n      await writeFile(pathname, content);\n    } catch (error) {\n      return Promise.reject(error);\n    }\n  });\n\n  // Helper: Parse file content based on scope type\n  const parseFileByType = async (fileContent, scopeType, format) => {\n    switch (scopeType) {\n      case 'request':\n        return await parseRequestViaWorker(fileContent, { format });\n      case 'folder':\n        return parseFolder(fileContent, { format });\n      case 'collection':\n        return parseCollection(fileContent, { format });\n      default:\n        throw new Error(`Invalid scope type: ${scopeType}`);\n    }\n  };\n\n  const stringifyByType = async (data, scopeType, collectionRoot, format) => {\n    switch (scopeType) {\n      case 'request':\n        return await stringifyRequestViaWorker(data, { format });\n      case 'folder':\n        return stringifyFolder(data, { format });\n      case 'collection':\n        return stringifyCollection(collectionRoot, data, { format });\n      default:\n        throw new Error(`Invalid scope type: ${scopeType}`);\n    }\n  };\n\n  // Helper: Update or create variable in array\n  const updateOrCreateVariable = (variables, variable) => {","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/collection.js#L661-L697","documentation":"Thrown by the parseFileByType helper (used by 'renderer:update-variable-in-file') when scopeType is not one of 'request', 'folder', or 'collection'. The switch dispatches to parseRequestViaWorker / parseFolder / parseCollection and hits the default arm on any other value.","triggerScenarios":"Invoking update-variable-in-file (or any handler using parseFileByType) with scopeType undefined, null, an empty string, a typo like 'requests' or 'Folder', or a future/unexpected value.","commonSituations":"A refactor that changes the scope constant set without updating callers. A typo in the renderer payload. An older renderer talking to a newer main process whose scope names diverged.","solutions":["Pass only 'request', 'folder', or 'collection' as scopeType.","Define the allowed set as a shared constant/enum imported by both renderer and main.","Validate scopeType against the allowed set on the renderer side before invoking the IPC."],"exampleFix":"// before\nawait window.ipcRenderer.invoke('renderer:update-variable-in-file', pathname, variable, 'requests', root, format);\n\n// after\nconst SCOPE = ['request', 'folder', 'collection'];\nif (!SCOPE.includes(scopeType)) throw new Error(`bad scope: ${scopeType}`);\nawait window.ipcRenderer.invoke('renderer:update-variable-in-file', pathname, variable, scopeType, root, format);","handlingStrategy":"type-guard","validationCode":"const SCOPES = new Set(['request', 'folder', 'collection']);\nif (!SCOPES.has(scopeType)) throw new Error(`unsupported scopeType: ${scopeType}`);\nawait window.ipcRenderer.invoke('renderer:update-variable-in-file', pathname, variable, scopeType, root, format);","typeGuard":"function isScopeType(v) {\n  return v === 'request' || v === 'folder' || v === 'collection';\n}","tryCatchPattern":"try {\n  await window.ipcRenderer.invoke('renderer:update-variable-in-file', pathname, variable, scopeType, root, format);\n} catch (e) {\n  if (/Invalid scope type/.test(e.message)) {\n    // log and surface a programming error to the developer\n  } else throw e;\n}","preventionTips":["Share a single SCOPE_TYPE constant between renderer and main.","Treat an invalid scopeType as a programming bug, not a user error — fail loud in dev.","Re-run type checks after refactors that touch scope enums."],"tags":["ipc","validation","programming-error","bruno"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}