{"record":{"id":"96c2c63da4f43b25","repo":"danielmiessler/Fabric","slug":"invalid-response-format-missing-vendors-data","errorCode":null,"errorMessage":"Invalid response format: missing vendors data","messagePattern":"Invalid response format: missing vendors data","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/src/lib/api/models.ts","lineNumber":10,"sourceCode":"import { api } from './base';\nimport type { VendorModel, ModelsResponse } from '$lib/interfaces/model-interface';\n\nexport const modelsApi = {\n  async getAvailable(): Promise<VendorModel[]> {\n    try {\n      const response = await api.fetch<ModelsResponse>('/models/names');\n      \n      if (!response.data?.vendors) {\n        throw new Error('Invalid response format: missing vendors data');\n      }\n      \n      // The server sends null for the model list of a vendor that it can find\n      // no models for, because an empty slice in Go becomes null in JSON.\n      // Ollama does this when it is in the configuration but serves no models.\n      // Skip such a vendor: one of them must not hide the models of the others.\n      return Object.entries(response.data.vendors).flatMap(([vendor, models]) =>\n        Array.isArray(models)\n          ? models.map(model => ({\n              name: model,\n              vendor\n            }))\n          : []\n      );\n    } catch (error) {\n      console.error(\"Failed to fetch models:\", error);\n      throw error;\n    }","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/danielmiessler/Fabric/blob/338b89cfe97ab2d12ce30ce8b5449857a841366d/web/src/lib/api/models.ts#L1-L28","documentation":"modelsApi.getAvailable() expects { vendors: Record<string, string[]> } from GET /api/models/names and throws when response.data.vendors is missing. The endpoint exists (HTTP succeeded) but the payload shape does not match, so the client cannot enumerate vendor models.","triggerScenarios":"Backend /api/models/names returning { data: null } because no vendors are configured, returning { error } consumed as null data, or a backend version whose response schema predates the vendors field.","commonSituations":"Fresh install with no model vendors configured in Fabric; Ollama/registry endpoints down so the backend reports zero vendors; frontend newer than the backend (schema drift after upgrade).","solutions":["curl /api/models/names and inspect the payload: is data null, or shaped differently?","Configure at least one model vendor in the backend and retry","If schema drift, align frontend/backend versions or tolerate a missing vendors field as an empty list"],"exampleFix":"// before\nif (!response.data?.vendors) {\n  throw new Error('Invalid response format: missing vendors data');\n}\n\n// after\nconst vendors = response.data?.vendors;\nif (!vendors) {\n  if (response.error) throw new Error(response.error);\n  return []; // no vendors configured, not a hard failure\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isVendorsPayload(d: unknown): d is { vendors: Record<string, string[]> } {\n  return typeof d === 'object' && d !== null\n    && typeof (d as any).vendors === 'object' && (d as any).vendors !== null;\n}","tryCatchPattern":"try { models = await modelsApi.getAvailable(); }\ncatch (e) {\n  if (e instanceof Error && e.message.includes('missing vendors')) models = []; // show 'no vendors configured'\n  else throw e;\n}","preventionTips":["Validate response shape with a guard before trusting it","Return [] for zero vendors instead of throwing so the UI can render an empty state","Pin frontend and backend versions together during upgrades"],"tags":["api-client","schema-mismatch","models","validation"],"backgroundTag":null,"analyzedSha":"338b89cfe97ab2d12ce30ce8b5449857a841366d","analyzedAt":"2026-08-15T11:38:51.759Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}