{"record":{"id":"d19e2ab1a40dd813","repo":"Mintplex-Labs/anything-llm","slug":"preset-not-found","errorCode":null,"errorMessage":"Preset not found","messagePattern":"Preset not found","errorType":"http","errorClass":null,"httpStatus":404,"severity":"error","filePath":"server/endpoints/system.js","lineNumber":1365,"sourceCode":"        const { command, prompt, description } = reqBody(request);\n        const formattedCommand = SlashCommandPresets.formatCommand(\n          String(command)\n        );\n\n        if (isReservedCommand(formattedCommand)) {\n          return response.status(400).json({\n            message:\n              \"Cannot update a preset to use a command that matches a system command\",\n          });\n        }\n\n        // Valid user running owns the preset if user session is valid.\n        const ownsPreset = await SlashCommandPresets.get({\n          userId: user?.id ?? null,\n          id: Number(slashCommandId),\n        });\n        if (!ownsPreset)\n          return response.status(404).json({ message: \"Preset not found\" });\n\n        const updates = {\n          command: formattedCommand,\n          prompt: String(prompt),\n          description: String(description),\n        };\n\n        const preset = await SlashCommandPresets.update(\n          Number(slashCommandId),\n          updates\n        );\n        if (!preset) return response.sendStatus(422);\n        response.status(200).json({ preset: { ...ownsPreset, ...updates } });\n      } catch (error) {\n        console.error(\"Error updating slash command preset:\", error);\n        response.status(500).json({ message: \"Internal server error\" });\n      }\n    }","sourceCodeStart":1347,"sourceCodeEnd":1383,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/endpoints/system.js#L1347-L1383","documentation":"Returned as 404 by PUT /system/slash-command-presets/:slashCommandId when SlashCommandPresets.get({userId, id}) finds no row — the lookup is scoped to the current user's id (or null in single-user mode). Note the model's get() also swallows Prisma errors and returns null, so a database failure produces the same 404.","triggerScenarios":"PUT /system/slash-command-presets/999 where preset 999 belongs to a different user (userId clause mismatches); updating a preset that was already deleted; passing a non-numeric slashCommandId (Number() yields NaN, no row matches); a Prisma exception inside get() (which catches and returns null).","commonSituations":"Stale preset list in the UI after the row was removed on another device or tab; multi-user-mode token belongs to a different account than the preset owner; DB connection blips surfacing as misleading 404s because the model swallows errors.","solutions":["Verify the preset id exists and belongs to the logged-in user with GET /system/slash-command-presets before the PUT.","Refresh the preset list in the client when a 404 arrives and remove the stale row from the UI.","If it persists for presets you own, check server logs for the console.error from the model — get() returning null on a DB error looks identical to 'not found'."],"exampleFix":"// before\nconst res = await api.put(`/system/slash-command-presets/${id}`, payload);\nif (res.status === 404) throw new Error('bug?');\n\n// after\nconst res = await api.put(`/system/slash-command-presets/${id}`, payload);\nif (res.status === 404) {\n  // row gone or not owned by this user — drop it from local state\n  removePresetLocally(id);\n  return;\n}","handlingStrategy":"validation","validationCode":"const mine = await api.get('/system/slash-command-presets');\nconst exists = mine.presets.some((p) => p.id === Number(id));\nif (!exists) removePresetLocally(id);","typeGuard":"const isOwnedPreset = (preset, userId) =>\n  preset != null && (preset.userId === userId || preset.userId === null);","tryCatchPattern":"try { await updatePreset(id, payload); }\ncatch (e) { if (e.status === 404) syncPresetList(); else throw e; }","preventionTips":["Always scope UI actions to rows from the latest GET for the current session.","Treat 404 on update as a signal to refresh, not to retry.","Remember the model swallows DB errors as null — persistent 404s on owned presets warrant log inspection."],"tags":["slash-commands","presets","not-found","ownership"],"backgroundTag":"resource-not-found","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}