Mintplex-Labs/anything-llm · error · Error

data.message || "Error creating slash command preset."

Error message

data.message || "Error creating slash command preset."

What it means

Thrown by createSlashCommandPreset in the AnythingLLM frontend when POST /api/system/slash-command-presets responds non-2xx. It prefers the server's data.message (validation detail) over the generic fallback. Presets are per-user command shortcuts, and the server validates the submitted shape before inserting.

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 3aec848f28)

Solutions

  1. Ensure presetData carries every required field (command, name, etc.) with expected types before submitting.
  2. Pick a command string that does not duplicate an existing preset for the same user.
  3. Read the returned `error` — when the server supplies data.message it names the failing field.
  4. Check server logs if the failure is a database error rather than validation.
Defensive patterns

Strategy: validation

Validate before calling

// run before System.createSlashCommandPreset
function validPreset(p) {
  return (
    typeof p?.command === 'string' && p.command.trim().length > 0 &&
    typeof p?.name === 'string' && p.name.trim().length > 0
  );
}
if (!validPreset(presetData)) throw new Error('Command and name are required');

Type guard

/** @param {any} r @returns {r is {preset: object, error: null}} */
function isPresetCreated(r) {
  return typeof r === 'object' && r !== null && r.preset != null && r.error === null;
}

Try / catch

const { preset, error } = await System.createSlashCommandPreset(presetData);
if (error) {
  showPresetError(error); // server data.message names the failing field
  return;
}

Prevention

When it happens

Trigger: Posting presetData missing required fields (empty command or name), with wrong-typed values, or with a command that already exists for the user (duplicate rejection); any database error during insert also lands here.

Common situations: Creating a preset whose command collides with an existing one; frontend form allowing empty submissions after a state reset; DB unavailable on self-hosted instances.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/4fcee36e22a4d865. Report an issue: GitHub.