Hmbown/CodeWhale · error
A provider and page loader are required.
Error message
A provider and page loader are required.
What it means
collectProviderModelPages paginates a provider's model catalog and requires a non-empty provider id plus a callable fetchPage loader. Anything else is a caller bug (it cannot know which provider's pages to fetch or how to fetch them), so it throws up front.
Solutions
- Pass a non-empty provider id string as the first argument.
- Pass the actual page-loader function (e.g. (url) => fetch(url).then(r => r.json())) as the second argument.
- Check the import of the loader function if it comes from another module (name typo yields undefined).
Example fix
// before const models = await collectProviderModelPages(providerId, loaderUrl); // after const models = await collectProviderModelPages(providerId, (url) => fetch(url).then((r) => r.json()));
Defensive patterns
Strategy: validation
Validate before calling
if (providerId && typeof fetchPage === 'function') {
const pages = await collectProviderModelPages(providerId, fetchPage);
} Type guard
function canCollect(providerId, fetchPage) {
return String(providerId || '').trim().length > 0 && typeof fetchPage === 'function';
} Try / catch
try {
const pages = await collectProviderModelPages(providerId, fetchPage);
} catch (e) {
console.error('collectProviderModelPages misused:', e.message);
} Prevention
- Assert loader arguments with unit tests for the pagination helper.
- Import the loader by name and verify it is not undefined at call time.
- Keep provider id and loader wiring together in one call site.
When it happens
Trigger: Calling collectProviderModelPages('') or with a non-function second argument (undefined when an optional dependency failed to load, or a value mistakenly passed instead of a function).
Common situations: Refactoring left the fetch callback undefined; provider id lost from scope and passed as empty string; tests or callers invoking the helper directly with wrong arity.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Choose both a provider and a model.
- custom provider ' ' must set [providers. ].kind =…
- Invalid default_text_model
- Invalid provider ' ': expected .
- ` ` is not a valid provider id. Ids are 1-64 characters of…
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/b1e60a26d6c05ccc.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/runtime_web/app.mjs:653
}
const PROVIDER_MODELS_PAGE_SIZE = 250;
const MAX_PROVIDER_MODELS = 10_000;
const MAX_PROVIDER_MODEL_PAGES = Math.ceil(
MAX_PROVIDER_MODELS / PROVIDER_MODELS_PAGE_SIZE,
);
/**
* Load every bounded page of one provider catalog.
*
* `fetchPage` is injected so the browser client can retain its authenticated
* Runtime API boundary and tests can prove catalogs larger than one page are
* not silently truncated. Cursors are opaque and may never repeat.
*/
export async function collectProviderModelPages(providerId, fetchPage) {
const provider = String(providerId || "").trim();
if (!provider || typeof fetchPage !== "function") {
throw new Error("A provider and page loader are required.");
}
const entries = [];
const seenCursors = new Set();
let expectedTotal;
let cursor = "";
for (let page = 0; page < MAX_PROVIDER_MODEL_PAGES; page += 1) {
const query = new URLSearchParams({ limit: String(PROVIDER_MODELS_PAGE_SIZE) });
if (cursor) query.set("cursor", cursor);
const response = await fetchPage(
`/v1/providers/${encodeURIComponent(provider)}/models?${query.toString()}`,
);
if (String(response?.provider || "") !== provider) {
throw new Error("The Runtime returned a model page for a different provider.");
}
if (!Array.isArray(response?.models)
|| response.models.length > PROVIDER_MODELS_PAGE_SIZE
|| !Number.isSafeInteger(response.total)View on GitHub (pinned to 73e0f67d83)