Mintplex-Labs/anything-llm · warning

${response.error || "Failed to create slash command"}

Error message

${response.error || "Failed to create slash command"}

What it means

Thrown inside createSlashCommand's promise chain when the POST to /community-hub/slash-command/create returns a non-OK HTTP status. It prefers the server-supplied response.error and falls back to the static 'Failed to create slash command' string when the JSON body omits an error field. The throw is caught by the trailing .catch and reshaped into {success:false, error:e.message}, so callers receive a result object rather than a thrown exception.

Source

Thrown at frontend/src/models/communityHub.js:223

   * @param {Object} data - The slash command data
   * @param {string} data.name - The name of the command
   * @param {string} data.description - The description of the command
   * @param {string} data.command - The actual command text
   * @param {string} data.prompt - The prompt for the command
   * @param {string[]} data.tags - Array of tags
   * @param {string} data.visibility - Either 'public' or 'private'
   * @returns {Promise<{success: boolean, error: string | null}>}
   */
  createSlashCommand: async (data) => {
    return await fetch(`${API_BASE}/community-hub/slash-command/create`, {
      method: "POST",
      headers: baseHeaders(),
      body: JSON.stringify(data),
    })
      .then(async (res) => {
        const response = await res.json();
        if (!res.ok)
          throw new Error(response.error || "Failed to create slash command");
        return { success: true, error: null, itemId: response.item?.id };
      })
      .catch((e) => ({
        success: false,
        error: e.message,
      }));
  },
};

export default CommunityHub;

View on GitHub (pinned to 526360e320)

Solutions

  1. Read the returned object.error first - it carries the server's actual reason.
  2. Ensure data.visibility is exactly 'public' or 'private' and name/command are non-empty.
  3. Refresh auth (re-login) if baseHeaders is sending a stale token.
  4. Check the backend create route for uniqueness/validation rules before retrying.

Example fix

// before
const res = await CommunityHub.createSlashCommand(data);
if (!res.success) { /* res.error may be only the static string */ }

// after
const payload = {
  ...data,
  visibility: ['public','private'].includes(data.visibility) ? data.visibility : 'private',
};
const res = await CommunityHub.createSlashCommand(payload);
if (!res.success) showToast(res.error || 'Could not create slash command', 'error');
Defensive patterns

Strategy: validation

Validate before calling

function validateSlashCommandInput(data) {
  const errors = [];
  if (!data?.name?.trim()) errors.push('name is required');
  if (!data?.command?.trim()) errors.push('command is required');
  if (!['public','private'].includes(data?.visibility))
    errors.push("visibility must be 'public' or 'private'");
  return errors;
}
// before the call:
const errs = validateSlashCommandInput(data);
if (errs.length) return { success: false, error: errs.join('; ') };

Type guard

/** @param {unknown} r */
function isSlashCommandResult(r) {
  return typeof r === 'object' && r !== null
    && typeof r.success === 'boolean'
    && (r.error === null || typeof r.error === 'string');
}

Try / catch

try {
  const res = await CommunityHub.createSlashCommand(data);
  if (!res.success) handleUserError(res.error);
} catch (e) {
  // only transport/JSON-parse failures reach here
  handleTransportError(e);
}

Prevention

When it happens

Trigger: POSTing a payload missing required fields (name, command, visibility), sending a visibility value other than 'public'/'private', an expired or missing auth token in baseHeaders, or attempting to create a slash command whose name already exists in the workspace.

Common situations: Form submitted with visibility left empty or undefined; session token expired between page load and submit; duplicate slash-command name collision; backend validation rejecting an over-long command string.

Related errors


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