Mintplex-Labs/anything-llm · error

Preset not found

Error message

Preset not found

What it means

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.

Source

Thrown at server/endpoints/system.js:1365

        const { command, prompt, description } = reqBody(request);
        const formattedCommand = SlashCommandPresets.formatCommand(
          String(command)
        );

        if (isReservedCommand(formattedCommand)) {
          return response.status(400).json({
            message:
              "Cannot update a preset to use a command that matches a system command",
          });
        }

        // Valid user running owns the preset if user session is valid.
        const ownsPreset = await SlashCommandPresets.get({
          userId: user?.id ?? null,
          id: Number(slashCommandId),
        });
        if (!ownsPreset)
          return response.status(404).json({ message: "Preset not found" });

        const updates = {
          command: formattedCommand,
          prompt: String(prompt),
          description: String(description),
        };

        const preset = await SlashCommandPresets.update(
          Number(slashCommandId),
          updates
        );
        if (!preset) return response.sendStatus(422);
        response.status(200).json({ preset: { ...ownsPreset, ...updates } });
      } catch (error) {
        console.error("Error updating slash command preset:", error);
        response.status(500).json({ message: "Internal server error" });
      }
    }

View on GitHub (pinned to 20f6d3546c)

Solutions

  1. Verify the preset id exists and belongs to the logged-in user with GET /system/slash-command-presets before the PUT.
  2. Refresh the preset list in the client when a 404 arrives and remove the stale row from the UI.
  3. 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'.

Example fix

// before
const res = await api.put(`/system/slash-command-presets/${id}`, payload);
if (res.status === 404) throw new Error('bug?');

// after
const res = await api.put(`/system/slash-command-presets/${id}`, payload);
if (res.status === 404) {
  // row gone or not owned by this user — drop it from local state
  removePresetLocally(id);
  return;
}
Defensive patterns

Strategy: validation

Validate before calling

const mine = await api.get('/system/slash-command-presets');
const exists = mine.presets.some((p) => p.id === Number(id));
if (!exists) removePresetLocally(id);

Type guard

const isOwnedPreset = (preset, userId) =>
  preset != null && (preset.userId === userId || preset.userId === null);

Try / catch

try { await updatePreset(id, payload); }
catch (e) { if (e.status === 404) syncPresetList(); else throw e; }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18). Data as JSON: /api/errors/d19e2ab1a40dd813. Report an issue: GitHub.