{"record":{"id":"742d11e1c371cda6","repo":"moeru-ai/airi","slug":"failed-to-update-provider-config","errorCode":null,"errorMessage":"Failed to update provider config","messagePattern":"Failed to update provider config","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/stage-ui/src/services/inference-service-providers.ts","lineNumber":196,"sourceCode":"\n  async function patchConfigRemote(\n    client: InferenceServiceProvidersRemoteClient,\n    providerId: string,\n    config: Record<string, unknown>,\n    status: ProviderValidationStatus,\n    options?: InferenceServiceProviderServiceOptions,\n  ): Promise<InferenceServiceProvider> {\n    options?.abortSignal?.throwIfAborted()\n    const res = await client.api.v1.providers[':id'].$patch({\n      param: { id: providerId },\n      json: {\n        config,\n        validated: status === 'configured',\n        validationBypassed: status === 'bypassed',\n      },\n    }, requestOptions(options))\n    if (!res.ok)\n      throw new Error('Failed to update provider config')\n\n    const item = await res.json()\n    options?.abortSignal?.throwIfAborted()\n    return normalize(item)\n  }\n\n  return {\n    buildLocal,\n    fetchRemote,\n    createRemote,\n    deleteRemote,\n    patchConfigRemote,\n  }\n}\n\nexport const inferenceServiceProvidersService = createInferenceServiceProvidersService()\n","sourceCodeStart":178,"sourceCodeEnd":213,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/packages/stage-ui/src/services/inference-service-providers.ts#L178-L213","documentation":"Thrown by InferenceServiceProvidersService.patchConfigRemote when PATCH /v1/providers/:id returns non-ok. The service patches config plus validated/validationBypassed flags derived from the ProviderValidationStatus, then normalizes the response. Failure aborts before normalize.","triggerScenarios":"client.api.v1.providers[':id'].$patch({ param: { id }, json: { config, validated, validationBypassed } }) resolves with ok=false. Typical: 400/422 (config failed server-side validation, e.g. bad apiKey), 401/403 (not authenticated / not owner), 404 (provider deleted), 500 (server).","commonSituations":"Saving a provider config with an invalid apiKey that fails the backend's validation probe; editing a concurrently-deleted provider; expired session; setting status to 'configured' while config is actually invalid.","solutions":["Run client-side config validation (and a live credential check if possible) before PATCHing.","Handle 404 by refreshing the provider list and removing the stale entry.","Re-authenticate on 401/403; on 422 surface the field errors to the form.","Capture res.status and server detail for accurate feedback."],"exampleFix":"// before\nif (!res.ok)\n  throw new Error('Failed to update provider config')\n\n// after\nif (!res.ok) {\n  if (res.status === 404)\n    throw new NotFoundError(`Provider ${providerId} not found`)\n  const detail = await res.json().catch(() => null)\n  throw new ProviderConfigError(`Failed to update provider config (status ${res.status})`, detail)\n}","handlingStrategy":"validation","validationCode":"function validateProviderConfig(providerId: string, config: Record<string, unknown>, status: ProviderValidationStatus): string[] {\n  const errors: string[] = []\n  if (status === 'configured') {\n    // definition-specific required-field checks (e.g. apiKey present)\n    if (!config.apiKey)\n      errors.push('apiKey is required to mark provider as configured')\n  }\n  return errors\n}\n\nconst issues = validateProviderConfig(providerId, config, status)\nif (issues.length)\n  throw new Error('Invalid provider config: ' + issues.join(', '))\nawait patchConfigRemote(client, providerId, config, status)","typeGuard":null,"tryCatchPattern":"try {\n  return await patchConfigRemote(client, providerId, config, status)\n}\ncatch (error) {\n  // Patch service to expose status; on 404 refresh list, on 401/403 re-auth, on 422 show field errors.\n  throw error\n}","preventionTips":["Run client-side config validation (and a live credential probe if available) before PATCHing.","Do not set status to 'configured' unless the config has passed validation.","Embed res.status and server validation detail in the service error for accurate form feedback."],"tags":["network","http","providers","api","validation","auth"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}