Mintplex-Labs/anything-llm · warning

Not Found

Error message

Not Found

What it means

Returned by POST /v1/workspace/:slug/update-pin as HTTP 404 when the document is not found. The handler at server/endpoints/api/workspace/index.js:588 queries Document.get({ workspaceId: workspace.id, docpath: docPath }) and if the document does not exist, returns `response.sendStatus(404).end()`. IMPORTANT: this handler has a latent bug — it does NOT null-check the `workspace` variable before accessing workspace.id (line 585), so if the workspace slug is invalid, workspace is null and accessing workspace.id throws, hitting the catch block which returns 500 (not 404). The 404 specifically means the workspace WAS found but the document at the given docPath within it was not.

Source

Thrown at server/endpoints/api/workspace/index.js:588

        }
      }
      #swagger.responses[404] = {
        description: 'Document not found'
      }
      #swagger.responses[500] = {
        description: 'Internal Server Error'
      }
      */
      try {
        const { slug = null } = request.params;
        const { docPath, pinStatus = false } = reqBody(request);
        const workspace = await Workspace.get({ slug: String(slug) });

        const document = await Document.get({
          workspaceId: workspace.id,
          docpath: docPath,
        });
        if (!document) return response.sendStatus(404).end();

        await Document.update(document.id, { pinned: pinStatus });
        return response
          .status(200)
          .json({ message: "Pin status updated successfully" })
          .end();
      } catch (error) {
        console.error("Error processing the pin status update:", error);
        return response.status(500).end();
      }
    }
  );

  app.post(
    "/v1/workspace/:slug/chat",
    [validApiKey],
    async (request, response) => {
      /*

View on GitHub (pinned to 526360e320)

Solutions

  1. Fetch the workspace's document list first: GET /v1/workspace/:slug to see valid docPath values.
  2. Ensure docPath matches the exact format stored in the documents table, including the 'custom-documents/' prefix and hash suffix.
  3. If the document was recently removed via update-embeddings, it cannot be pinned — re-add it first.
  4. Check that the docPath belongs to the correct workspace — the same file path in different workspaces are different Document records.

Example fix

// before — guessing the docPath
await fetch('/v1/workspace/my-ws/update-pin', {
  method: 'POST',
  body: JSON.stringify({ docPath: 'myfile.json', pinStatus: true })
});

// after — fetch the correct docPath from the workspace first
const { workspace } = await (await fetch('/v1/workspace/my-ws', {
  headers: { Authorization: `Bearer ${API_KEY}` }
})).json();
const doc = workspace[0].documents.find(d => d.title === 'myfile');
await fetch('/v1/workspace/my-ws/update-pin', {
  method: 'POST',
  body: JSON.stringify({ docPath: doc.docpath, pinStatus: true })
});
Defensive patterns

Strategy: validation

Validate before calling

// Verify the document exists in the workspace before pinning
async function verifyDocumentForPinning(slug, docPath, apiKey) {
  const res = await fetch(`/v1/workspace/${slug}`, {
    headers: { Authorization: `Bearer ${apiKey}` }
  });
  const { workspace } = await res.json();
  if (!workspace || workspace.length === 0) return { ok: false, error: 'Workspace not found' };
  const docs = workspace[0].documents || [];
  return docs.some(d => d.docpath === docPath)
    ? { ok: true }
    : { ok: false, error: `Document path '${docPath}' not found in workspace` };
}

Try / catch

try {
  const check = await verifyDocumentForPinning(slug, docPath, API_KEY);
  if (!check.ok) throw new Error(check.error);
  const res = await fetch(`/v1/workspace/${slug}/update-pin`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${API_KEY}` },
    body: JSON.stringify({ docPath, pinStatus })
  });
  if (res.status === 404) throw new Error('Document not found — may have been removed');
  if (res.status === 500) throw new Error('Server error — workspace may not exist (null-safety bug)');
  return await res.json();
} catch (e) { console.error(e); }

Prevention

When it happens

Trigger: POST /v1/workspace/valid-slug/update-pin with { docPath: 'custom-documents/nonexistent.json' } where the document path does not match any document in that workspace. Also triggered by a docPath that exists in a different workspace, or by using a document name without the full path prefix (e.g., 'file.json' instead of 'custom-documents/file.json-hash.json').

Common situations: Pinning a document that was removed from the workspace via update-embeddings. Using a truncated or incorrect docPath. The document was moved to a different workspace. Referencing a document by its display name rather than its stored docpath.

Related errors


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