Mintplex-Labs/anything-llm · error

${response.error || "Failed to create agent flow"}

Error message

${response.error || "Failed to create agent flow"}

What it means

Thrown from `createAgentFlow` on a non-ok `POST /api/community-hub/agent-flow/create`. Reads `response.error`, falling back to 'Failed to create agent flow'. Unlike sibling methods, this one has NO `.catch` — if `res.json()` rejects or the throw propagates, the promise rejects to the caller, so callers MUST handle the rejection themselves.

Source

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

        success: false,
        error: e.message,
      }));
  },

  /**
   * Create a new agent flow in the community hub
   * @param {Object} data - The agent flow data
   * @returns {Promise<{success: boolean, error: string | null}>}
   */
  createAgentFlow: async (data) => {
    return await fetch(`${API_BASE}/community-hub/agent-flow/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 agent flow");
      return { success: true, error: null, itemId: response.item?.id };
    });
  },

  /**
   * Create a new slash command in the community hub
   * @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",

View on GitHub (pinned to 526360e320)

Solutions

  1. Wrap the call in try/catch (or `.catch`) since this method does not catch internally.
  2. Validate the flow data (name non-empty, config is a serializable object) before posting.
  3. Read the rejection's message for the server's reason.
  4. Align this method with its siblings by adding a `.catch` returning `{ success: false, error: e.message }` for consistent caller handling.

Example fix

// before — no catch on the model; caller may get an unhandled rejection
const result = await CommunityHub.createAgentFlow(data);

// after — caller must catch; and consider patching the model for consistency
try {
  const result = await CommunityHub.createAgentFlow(data);
  if (!result.success) throw new Error(result.error || 'Failed to create agent flow');
} catch (e) {
  // handle e.message (server error or network failure)
}

// also patch the model (mirrors createSystemPrompt):
//   .catch((e) => ({ success: false, error: e.message }))
Defensive patterns

Strategy: try-catch

Validate before calling

function validateAgentFlowPayload(data) {
  if (!data || typeof data !== 'object') throw new Error('Agent flow data is required');
  if (typeof data.name !== 'string' || !data.name.trim()) throw new Error('Agent flow name is required');
  if (!data.config || typeof data.config !== 'object') throw new Error('Agent flow config is required');
}

Type guard

function isAgentFlowPayload(v) {
  return !!v && typeof v === 'object' && typeof v.name === 'string' && v.name.trim().length > 0 && !!v.config && typeof v.config === 'object';
}

Try / catch

// IMPORTANT: this model does NOT catch internally — wrap the call:
try {
  const result = await CommunityHub.createAgentFlow(data);
  if (!result?.success) showToast(result?.error || 'Failed to create agent flow');
} catch (e) {
  showToast(e.message); // network/parse failure
}

Prevention

When it happens

Trigger: Missing/invalid flow data (name, config), 401 non-admin, 409 duplicate flow name, 500 persistence error, malformed JSON body. Because there's no catch, any of these will reject the returned promise rather than return a `{ success, error }` object.

Common situations: Caller assumes a resolved `{success,error}` shape (like the sibling methods) and hits an unhandled rejection; incomplete flow config submitted; session expired.

Related errors


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