{"record":{"id":"548965393c4eef44","repo":"benweet/stackedit","slug":"unauthorized-name","errorCode":null,"errorMessage":"Unauthorized name.","messagePattern":"Unauthorized name\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/services/workspaceSvc.js","lineNumber":83,"sourceCode":"    }\n\n    // Return the new file item\n    return store.state.file.itemsById[id];\n  },\n\n  /**\n   * Make sanity checks and then create/update the folder/file in the store.\n   */\n  async storeItem(item) {\n    const id = item.id || utils.uid();\n    const sanitizedName = utils.sanitizeFilename(item.name);\n\n    if (item.type === 'folder' && forbiddenFolderNameMatcher.exec(sanitizedName)) {\n      await store.dispatch('modal/open', {\n        type: 'unauthorizedName',\n        item,\n      });\n      throw new Error('Unauthorized name.');\n    }\n\n    // Show warning dialogs\n    // If name has been stripped\n    if (sanitizedName !== constants.defaultName && sanitizedName !== item.name) {\n      await store.dispatch('modal/open', {\n        type: 'stripName',\n        item,\n      });\n    }\n\n    // Check if there is a path conflict\n    if (store.getters['workspace/currentWorkspaceHasUniquePaths']) {\n      const parentPath = store.getters.pathsByItemId[item.parentId] || '';\n      const path = parentPath + sanitizedName;\n      const items = store.getters.itemsByPath[path] || [];\n      if (items.some(itemWithSamePath => itemWithSamePath.id !== id)) {\n        await store.dispatch('modal/open', {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/benweet/stackedit/blob/6dce2a5e36b755a0c244522b48a06c91a2df0f59/src/services/workspaceSvc.js#L65-L101","documentation":"storeItem sanitizes an item's name before persisting it. If the item is a folder and its sanitized name matches forbiddenFolderNameMatcher (names reserved by the app), it opens an 'unauthorizedName' modal and throws 'Unauthorized name.' — the folder cannot use that reserved name.","triggerScenarios":"Creating or renaming a folder to a name matched by forbiddenFolderNameMatcher (reserved app names) during storeItem; calling storeItem programmatically with such a name bypassing the modal-only UX flow.","commonSituations":"Users naming a folder like an internal route/reserved keyword; automated imports or scripts calling storeItem with unsanitized names; after a rename where trimming/case changes collide with the forbidden matcher.","solutions":["Choose a different folder name that does not match the reserved-name pattern.","Sanitize the name before calling storeItem and pre-check it against forbiddenFolderNameMatcher to fail fast with your own message.","If hit programmatically, catch the error and prompt the user for a new name instead of letting the throw propagate.","Check constants/regex for forbiddenFolderNameMatcher to know exactly which names are disallowed."],"exampleFix":"// before\nawait storeItem({ type: 'folder', name: 'data' }); // may throw 'Unauthorized name.'\n// after\nconst sanitized = utils.sanitizeName('data');\nif (constants.forbiddenFolderNameMatcher.exec(sanitized)) {\n  sanitized = `${sanitized}-folder`;\n}\nawait storeItem({ type: 'folder', name: sanitized });","handlingStrategy":"validation","validationCode":"import constants from '@/services/constants';\nconst sanitizedName = utils.sanitizeName(item.name);\nif (item.type === 'folder' && constants.forbiddenFolderNameMatcher.exec(sanitizedName)) {\n  throw new Error(`Folder name \"${sanitizedName}\" is reserved`); // before calling storeItem\n}","typeGuard":"function isAllowedFolderName(name) {\n  const sanitized = utils.sanitizeName(name);\n  return sanitized !== '' && !constants.forbiddenFolderNameMatcher.exec(sanitized);\n}","tryCatchPattern":"try {\n  await storeItem(item);\n} catch (err) {\n  if (err.message === 'Unauthorized name.') {\n    // prompt the user for a different folder name\n  } else throw err;\n}","preventionTips":["Validate folder names against forbiddenFolderNameMatcher before calling storeItem","Apply the same sanitize function the library uses so trimming/casing match","Provide UI-level inline validation for folder creation/renaming","Keep a list of reserved names handy when scripting bulk imports"],"tags":["validation","naming","folder","reserved-name"],"backgroundTag":"reserved-name-validation","analyzedSha":"6dce2a5e36b755a0c244522b48a06c91a2df0f59","analyzedAt":"2026-09-01T00:49:23.866Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}