odysseus-dev/odysseus · error · Error

Failed

Error message

Failed

What it means

Thrown in the diff/version-compare handler of static/js/document.js when GET /api/document/<id>/versions returns non-2xx. The unhelpful message 'Failed' replaces the status, so the console error (and the catch that follows) is the only diagnostic. It fires before any version comparison happens.

Source

Thrown at static/js/document.js:5780

      }
    });

    // Diff toggle button — compare current content against previous version
    const diffToggleBtn = document.getElementById('doc-diff-toggle-btn');
    if (diffToggleBtn) diffToggleBtn.addEventListener('click', async () => {
      if (_diffModeActive) {
        exitDiffMode(true);
        return;
      }
      if (!activeDocId) return;
      const ta = document.getElementById('doc-editor-textarea');
      if (!ta) return;
      const current = ta.value;

      // Fetch version history and compare against previous version
      try {
        const res = await fetch(`${API_BASE}/api/document/${activeDocId}/versions`);
        if (!res.ok) throw new Error('Failed');
        const versions = await res.json();
        if (versions.length < 2) {
          if (uiModule) uiModule.showToast('No previous version to compare');
          return;
        }
        // versions are sorted desc — [0] is latest, [1] is previous
        const prevContent = versions[1].content || '';
        if (prevContent === current) {
          if (uiModule) uiModule.showToast('No changes from previous version');
          return;
        }
        enterDiffMode(prevContent, current);
      } catch {
        if (uiModule) uiModule.showError('Failed to load version history');
      }
    });

    // Export PDF (form-backed markdown docs)

View on GitHub (pinned to f9235ebbf1)

Solutions

  1. Reproduce with the Network tab open and note the real status code for /api/document/<id>/versions.
  2. If 404, reopen the document from the Library — the local tab references a deleted doc.
  3. Improve the message to include res.status (and res.statusText) so future hits are self-describing.
  4. Verify auth/session if 401/403.

Example fix

// before
if (!res.ok) throw new Error('Failed');

// after
if (!res.ok) throw new Error(`Failed to load versions: HTTP ${res.status}`);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!activeDocId) return;
const doc = docs.get(activeDocId);
if (!doc) return; // no local doc to diff

Try / catch

try {
  const res = await fetch(`${API_BASE}/api/document/${activeDocId}/versions`, { credentials: 'same-origin' });
  if (!res.ok) throw new Error(`Failed to load versions: HTTP ${res.status}`);
  const versions = await res.json();
  if (!Array.isArray(versions)) throw new Error('Unexpected versions payload');
  if (versions.length < 2) { if (uiModule) uiModule.showToast('No previous version to compare'); return; }
} catch (e) {
  if (uiModule) uiModule.showError('Could not load version history');
}

Prevention

When it happens

Trigger: Clicking the compare/diff action on a document that was deleted server-side (404), with an expired session (401), or while the backend is down (network TypeError would actually be thrown by fetch itself and bypass this line).

Common situations: Comparing versions of a doc whose autosave 404s were already being swallowed; local tab pointing at a document purged by server-side cleanup; API route missing after downgrade.

Related errors


AI-assisted analysis of odysseus-dev/odysseus@f9235ebbf1 (2026-08-14). Data as JSON: /api/errors/86fa84133a6db845. Report an issue: GitHub.