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
- Read the returned object.error first - it carries the server's actual reason.
- Ensure data.visibility is exactly 'public' or 'private' and name/command are non-empty.
- Refresh auth (re-login) if baseHeaders is sending a stale token.
- 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
- Validate visibility against the allowed enum before submit.
- Centralize auth-token refresh so baseHeaders never sends a stale token.
- Branch on the returned result object, not a try/catch, since the model already swallows throws.
- Surface res.error to the user instead of discarding it.
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
- Type "${type}" is not a valid type to sync.
- ${response.error || "Failed to update settings"}
- ${response.error || "Failed to create system prompt"}
- ${response.error || "Failed to create agent flow"}
- ${res.reason}
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/697611d26d99ae82.
Report an issue: GitHub.