{"record":{"id":"f55e828b8cded1b3","repo":"Mintplex-Labs/anything-llm","slug":"error-creating-slash-command-preset","errorCode":null,"errorMessage":"Error creating slash command preset.","messagePattern":"Error creating slash command preset\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/models/system.js","lineNumber":728,"sourceCode":"        return res.json();\n      })\n      .then((res) => res.presets)\n      .catch((e) => {\n        console.error(e);\n        return [];\n      });\n  },\n\n  createSlashCommandPreset: async function (presetData) {\n    return await fetch(`${API_BASE}/system/slash-command-presets`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify(presetData),\n    })\n      .then(async (res) => {\n        const data = await res.json();\n        if (!res.ok)\n          throw new Error(\n            data.message || \"Error creating slash command preset.\"\n          );\n        return data;\n      })\n      .then((res) => ({ preset: res.preset, error: null }))\n      .catch((e) => {\n        console.error(e);\n        return { preset: null, error: e.message };\n      });\n  },\n\n  updateSlashCommandPreset: async function (presetId, presetData) {\n    return await fetch(`${API_BASE}/system/slash-command-presets/${presetId}`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify(presetData),\n    })\n      .then(async (res) => {","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/frontend/src/models/system.js#L710-L746","documentation":"Thrown when POST /system/slash-command-presets returns non-2xx while creating a new preset. Unlike the apiKey errors, this handler reads the response body and prefers data.message before falling back to the static string, so the server-side validation message is surfaced. The .catch returns { preset: null, error }.","triggerScenarios":"Submitting presetData that fails server validation (missing required fields, name too long, duplicate command trigger), creating a preset while unauthenticated, or the DB write failing (unique-constraint violation, schema mismatch).","commonSituations":"Duplicate preset trigger/keyword already owned by another preset; presetData.command is empty after trim; DB schema migration left the presets table locked; multi-user concurrency where two sessions insert the same slug.","solutions":["Read the returned error string in the UI — it is the server's data.message, which is the precise validation reason.","Validate presetData shape (non-empty trigger, command, name) on the client before posting.","Check for an existing preset with the same trigger before submitting.","Inspect backend /system/slash-command-presets controller for the validation rules and ensure the payload matches."],"exampleFix":"// before — caller posts without checking\nconst { preset, error } = await System.createSlashCommandPreset({ command, name });\n\n// after — guard required fields first\nif (!presetData?.command?.trim()) {\n  return { preset: null, error: \"Command trigger is required.\" };\n}\nconst { preset, error } = await System.createSlashCommandPreset(presetData);","handlingStrategy":"validation","validationCode":"function isValidPresetData(p) {\n  return p && typeof p.command === 'string' && p.command.trim().length > 0\n    && typeof p.name === 'string' && p.name.trim().length > 0;\n}","typeGuard":"function isPresetCreateResult(x): x is { preset: object; error: null } {\n  return x && x.preset !== null && x.error === null;\n}","tryCatchPattern":"if (!isValidPresetData(presetData)) {\n  return { preset: null, error: 'Command and name are required.' };\n}\nconst { preset, error } = await System.createSlashCommandPreset(presetData);\nif (error) showToast(error);","preventionTips":["Client-validate required fields before posting to avoid round-tripping validation errors.","Check for an existing preset with the same trigger to prevent duplicate-key failures.","The returned error is the server's data.message — display it directly to the user."],"tags":["frontend","api-client","validation","crud","slash-commands"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}