Mintplex-Labs/anything-llm · warning · Error

res.reason

Error message

res.reason

What it means

Thrown by DataConnector.github.collect when the backend proxy at /ext/github/repo returns JSON with success:false. The thrown message is the backend's res.reason, surfaced to the caller as result.error after the .catch. This call walks repo contents on a branch honoring ignorePaths, so failures tend to originate from branch access or traversal rather than auth alone.

Source

Thrown at frontend/src/models/dataConnector.js:36

        })
        .then((data) => {
          return { branches: data?.branches || [], error: null };
        })
        .catch((e) => {
          console.error(e);
          showToast(e.message, "error");
          return { branches: [], error: e.message };
        });
    },
    collect: async function ({ repo, accessToken, branch, ignorePaths = [] }) {
      return await fetch(`${API_BASE}/ext/github/repo`, {
        method: "POST",
        headers: baseHeaders(),
        body: JSON.stringify({ repo, accessToken, branch, ignorePaths }),
      })
        .then((res) => res.json())
        .then((res) => {
          if (!res.success) throw new Error(res.reason);
          return { data: res.data, error: null };
        })
        .catch((e) => {
          console.error(e);
          return { data: null, error: e.message };
        });
    },
  },
  gitea: {
    branches: async ({ repo, accessToken }) => {
      return await fetch(`${API_BASE}/ext/gitea/branches`, {
        method: "POST",
        headers: baseHeaders(),
        cache: "force-cache",
        body: JSON.stringify({ repo, accessToken }),
      })
        .then((res) => res.json())
        .then((res) => {

View on GitHub (pinned to 526360e320)

Solutions

  1. Confirm the branch name exists via the branches() call before collecting.
  2. Pass ignorePaths as an array of glob strings to skip huge directories.
  3. Verify 'contents: read' scope on the token.
  4. If the repo is very large, narrow the collect with deeper ignorePaths or shard by directory.

Example fix

// before
const { data } = await DataConnector.github.collect({ repo, accessToken, branch });

// after
const { data, error } = await DataConnector.github.collect({
  repo, accessToken, branch: branch || 'main', ignorePaths: ['node_modules/**','*.lock'],
});
if (error) { showToast(`GitHub collect: ${error}`, 'error'); return; }
Defensive patterns

Strategy: validation

Validate before calling

function validateCollectArgs({ repo, accessToken, branch, ignorePaths }) {
  if (!/^[-.\w]+\/[-.\w]+$/.test(repo ?? '')) return 'repo must be "owner/name"';
  if (!branch?.trim()) return 'branch is required';
  if (!Array.isArray(ignorePaths)) return 'ignorePaths must be an array';
  return null;
}

Type guard

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

Try / catch

const { data, error } = await DataConnector.github.collect({ repo, accessToken, branch, ignorePaths });
if (error) { showToast(`GitHub collect: ${error}`, 'error'); return null; }
return data;

Prevention

When it happens

Trigger: Branch does not exist or has no commits; token lacks 'contents: read'; repo is empty; ignorePaths globs are malformed and break server-side filtering; repo is too large and the backend traversal times out.

Common situations: Default branch renamed from 'main' but caller still sends 'master'; monorepo traversal exceeds backend limits; ignorePaths sent as a string instead of an array; token scoped to a fork that lacks the requested branch.

Related errors


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