Mintplex-Labs/anything-llm · error · Error

Error creating slash command preset.

Error message

Error creating slash command preset.

What it means

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 }.

Source

Thrown at frontend/src/models/system.js:728

        return res.json();
      })
      .then((res) => res.presets)
      .catch((e) => {
        console.error(e);
        return [];
      });
  },

  createSlashCommandPreset: async function (presetData) {
    return await fetch(`${API_BASE}/system/slash-command-presets`, {
      method: "POST",
      headers: baseHeaders(),
      body: JSON.stringify(presetData),
    })
      .then(async (res) => {
        const data = await res.json();
        if (!res.ok)
          throw new Error(
            data.message || "Error creating slash command preset."
          );
        return data;
      })
      .then((res) => ({ preset: res.preset, error: null }))
      .catch((e) => {
        console.error(e);
        return { preset: null, error: e.message };
      });
  },

  updateSlashCommandPreset: async function (presetId, presetData) {
    return await fetch(`${API_BASE}/system/slash-command-presets/${presetId}`, {
      method: "POST",
      headers: baseHeaders(),
      body: JSON.stringify(presetData),
    })
      .then(async (res) => {

View on GitHub (pinned to 526360e320)

Solutions

  1. Read the returned error string in the UI — it is the server's data.message, which is the precise validation reason.
  2. Validate presetData shape (non-empty trigger, command, name) on the client before posting.
  3. Check for an existing preset with the same trigger before submitting.
  4. Inspect backend /system/slash-command-presets controller for the validation rules and ensure the payload matches.

Example fix

// before — caller posts without checking
const { preset, error } = await System.createSlashCommandPreset({ command, name });

// after — guard required fields first
if (!presetData?.command?.trim()) {
  return { preset: null, error: "Command trigger is required." };
}
const { preset, error } = await System.createSlashCommandPreset(presetData);
Defensive patterns

Strategy: validation

Validate before calling

function isValidPresetData(p) {
  return p && typeof p.command === 'string' && p.command.trim().length > 0
    && typeof p.name === 'string' && p.name.trim().length > 0;
}

Type guard

function isPresetCreateResult(x): x is { preset: object; error: null } {
  return x && x.preset !== null && x.error === null;
}

Try / catch

if (!isValidPresetData(presetData)) {
  return { preset: null, error: 'Command and name are required.' };
}
const { preset, error } = await System.createSlashCommandPreset(presetData);
if (error) showToast(error);

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/f55e828b8cded1b3. Report an issue: GitHub.