Budibase/budibase · error

Koa context must be supplied to logout.

Error message

Koa context must be supplied to logout.

What it means

Same failure mode as errorIndex 3 but raised at connection.ts:686 inside fetchSharePointListDocument's item-paging loop: GET /sites/{siteId}/lists/{listId}/items?$expand=fields (or a nextLink page) returned a non-ok status other than 401/403, after the built-in retry pass.

Source

Thrown at packages/backend-core/src/auth/auth.ts:191

    }

    await db.put(dbUser)

    await invalidateUser(userId)
  } catch (e) {
    console.error("Could not update OAuth details for current user", e)
  }
}

/**
 * Logs a user out from budibase. Re-used across account portal and builder.
 */
export async function platformLogout(opts: PlatformLogoutOpts) {
  const ctx = opts.ctx
  const userId = opts.userId
  const keepActiveSession = opts.keepActiveSession

  if (!ctx) throw new Error("Koa context must be supplied to logout.")

  const currentSession = getCookie<SessionCookie>(ctx, Cookie.Auth)
  let sessions = await getSessionsForUser(userId)

  if (currentSession && keepActiveSession) {
    sessions = sessions.filter(
      session => session.sessionId !== currentSession.sessionId
    )
  } else {
    // clear cookies
    clearCookie(ctx, Cookie.Auth)
  }

  const sessionIds = sessions.map(({ sessionId }) => sessionId)
  await invalidateSessions(userId, { sessionIds, reason: "logout" })
  await events.auth.logout(ctx.user?.email)
  await userCache.invalidateUser(userId)
}

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Check the status in the message: 404 → re-select the list (it no longer exists at that ID).
  2. For 429, reschedule the sync; Graph throttling on large lists is common — reduce $top or sync off-peak.
  3. For 400, verify siteId/listId are raw Graph resource IDs.
  4. Retry after confirming Graph service health; transient 5xx are retried 3 times already.
Defensive patterns

Strategy: retry

Validate before calling

// Confirm list still exists before streaming items
const list = await graph(`/sites/${siteId}/lists/${listId}?$select=id`)
if (!list?.id) throw new Error("SharePoint list no longer exists")

Type guard

const isTransientGraphError = (e: unknown): boolean => {
  const m = /\((\d+)\)\s*$/.exec(String((e as Error)?.message))
  return m ? ["429", "500", "502", "503", "504"].includes(m[1]) : false
}

Try / catch

try {
  await fetchSharePointListDocument(token, siteId, listId)
} catch (e) {
  if (isTransientGraphError(e)) {
    await new Promise(r => setTimeout(r, 30_000))
    return fetchSharePointListDocument(token, siteId, listId)
  }
  throw e
}

Prevention

When it happens

Trigger: The list items endpoint returns 404 (list deleted), 400 (bad query/listId), 429 (throttled past retries), or 5xx while streaming rows into the CSV.

Common situations: List deleted or moved to recycle bin after configuration; list exceeding Graph throttling limits during large syncs; listId copied from a non-Graph source; intermittent Graph 5xx.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/7c0caa2d1ad006d7. Report an issue: GitHub.