{"record":{"id":"697611d26d99ae82","repo":"Mintplex-Labs/anything-llm","slug":"response-error-failed-to-create-slash-comman","errorCode":null,"errorMessage":"${response.error || \"Failed to create slash command\"}","messagePattern":"\\$\\{response\\.error \\|\\| \"Failed to create slash command\"\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"frontend/src/models/communityHub.js","lineNumber":223,"sourceCode":"   * @param {Object} data - The slash command data\n   * @param {string} data.name - The name of the command\n   * @param {string} data.description - The description of the command\n   * @param {string} data.command - The actual command text\n   * @param {string} data.prompt - The prompt for the command\n   * @param {string[]} data.tags - Array of tags\n   * @param {string} data.visibility - Either 'public' or 'private'\n   * @returns {Promise<{success: boolean, error: string | null}>}\n   */\n  createSlashCommand: async (data) => {\n    return await fetch(`${API_BASE}/community-hub/slash-command/create`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify(data),\n    })\n      .then(async (res) => {\n        const response = await res.json();\n        if (!res.ok)\n          throw new Error(response.error || \"Failed to create slash command\");\n        return { success: true, error: null, itemId: response.item?.id };\n      })\n      .catch((e) => ({\n        success: false,\n        error: e.message,\n      }));\n  },\n};\n\nexport default CommunityHub;\n","sourceCodeStart":205,"sourceCodeEnd":234,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/frontend/src/models/communityHub.js#L205-L234","documentation":"Thrown inside createSlashCommand's promise chain when the POST to /community-hub/slash-command/create returns a non-OK HTTP status. It prefers the server-supplied response.error and falls back to the static 'Failed to create slash command' string when the JSON body omits an error field. The throw is caught by the trailing .catch and reshaped into {success:false, error:e.message}, so callers receive a result object rather than a thrown exception.","triggerScenarios":"POSTing a payload missing required fields (name, command, visibility), sending a visibility value other than 'public'/'private', an expired or missing auth token in baseHeaders, or attempting to create a slash command whose name already exists in the workspace.","commonSituations":"Form submitted with visibility left empty or undefined; session token expired between page load and submit; duplicate slash-command name collision; backend validation rejecting an over-long command string.","solutions":["Read the returned object.error first - it carries the server's actual reason.","Ensure data.visibility is exactly 'public' or 'private' and name/command are non-empty.","Refresh auth (re-login) if baseHeaders is sending a stale token.","Check the backend create route for uniqueness/validation rules before retrying."],"exampleFix":"// before\nconst res = await CommunityHub.createSlashCommand(data);\nif (!res.success) { /* res.error may be only the static string */ }\n\n// after\nconst payload = {\n  ...data,\n  visibility: ['public','private'].includes(data.visibility) ? data.visibility : 'private',\n};\nconst res = await CommunityHub.createSlashCommand(payload);\nif (!res.success) showToast(res.error || 'Could not create slash command', 'error');","handlingStrategy":"validation","validationCode":"function validateSlashCommandInput(data) {\n  const errors = [];\n  if (!data?.name?.trim()) errors.push('name is required');\n  if (!data?.command?.trim()) errors.push('command is required');\n  if (!['public','private'].includes(data?.visibility))\n    errors.push(\"visibility must be 'public' or 'private'\");\n  return errors;\n}\n// before the call:\nconst errs = validateSlashCommandInput(data);\nif (errs.length) return { success: false, error: errs.join('; ') };","typeGuard":"/** @param {unknown} r */\nfunction isSlashCommandResult(r) {\n  return typeof r === 'object' && r !== null\n    && typeof r.success === 'boolean'\n    && (r.error === null || typeof r.error === 'string');\n}","tryCatchPattern":"try {\n  const res = await CommunityHub.createSlashCommand(data);\n  if (!res.success) handleUserError(res.error);\n} catch (e) {\n  // only transport/JSON-parse failures reach here\n  handleTransportError(e);\n}","preventionTips":["Validate visibility against the allowed enum before submit.","Centralize auth-token refresh so baseHeaders never sends a stale token.","Branch on the returned result object, not a try/catch, since the model already swallows throws.","Surface res.error to the user instead of discarding it."],"tags":["api","community-hub","slash-command","validation","auth"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}