{"record":{"id":"09dba7b5731abb63","repo":"ThreeMammals/Ocelot","slug":"configurationrepositoryexception-config-errors","errorCode":null,"errorMessage":"ConfigurationRepositoryException(config.Errors)","messagePattern":"ConfigurationRepositoryException\\(config\\.Errors\\)","errorType":"exception","errorClass":"ConfigurationRepositoryException","httpStatus":null,"severity":"error","filePath":"src/Configuration/Repository/FileAndInternalConfigurationSetter.cs","lineNumber":37,"sourceCode":"    private readonly IFileConfigurationRepository _repo;\r\n\r\n    public FileAndInternalConfigurationSetter(\r\n        IInternalConfigurationRepository configRepo,\r\n        IInternalConfigurationCreator configCreator,\r\n        IFileConfigurationRepository repo)\r\n    {\r\n        _internalConfigRepo = configRepo;\r\n        _configCreator = configCreator;\r\n        _repo = repo;\r\n    }\r\n\r\n    public async Task SetAsync(FileConfiguration configuration, CancellationToken cancellationToken = default)\r\n    {\r\n        await _repo.SetAsync(configuration, cancellationToken);\r\n\r\n        var config = await _configCreator.Create(configuration);\r\n        if (config.IsError)\r\n            throw new ConfigurationRepositoryException(config.Errors);\r\n\r\n        _internalConfigRepo.AddOrReplace(config.Data);\r\n    }\r\n}\r\n","sourceCodeStart":19,"sourceCodeEnd":42,"githubUrl":"https://github.com/ThreeMammals/Ocelot/blob/d1f22d930430410bfd0233f5e9e4f92980cf7df0/src/Configuration/Repository/FileAndInternalConfigurationSetter.cs#L19-L42","documentation":"FileAndInternalConfigurationSetter.SetAsync creates the internal configuration from the FileConfiguration via IConfigurationCreator; if the creation result IsError, it throws ConfigurationRepositoryException carrying those errors. This aggregates all internal config validation/creation failures when setting the file-based configuration.","triggerScenarios":"IInternalConfigurationCreator.Create returns an Error result: invalid route/aggregates definitions, duplicate route keys, unsupported QoS/timeout options, downstream/upstream scheme problems, or validation errors from the config validator.","commonSituations":"Malformed ocelot.json routes (missing required fields, conflicting properties); invalid aggregation configuration; unsupported combinations after an Ocelot version upgrade; JSON with wrong types for options.","solutions":["Inspect the ConfigurationRepositoryException.Errors collection — each lists the specific config problem.","Validate ocelot.json against the Ocelot schema and the current version's validator rules.","Fix the offending route/aggregate fields reported in the errors (e.g. add missing ServiceName/DownstreamHostAndPorts).","Check for breaking config changes if this appeared after upgrading Ocelot.","Add a config validation step (IConfigurationValidator) before calling SetAsync in startup."],"exampleFix":"// before\nvar config = await _configCreator.Create(configuration);\nif (config.IsError)\n    throw new ConfigurationRepositoryException(config.Errors);\n// after (caller-side guard)\nvar validation = await configValidator.Validate(configuration);\nif (!validation.IsError) await setter.SetAsync(configuration);","handlingStrategy":"validation","validationCode":"var result = await configurationValidator.Validate(fileConfiguration);\nif (result.IsError)\n{\n    foreach (var e in result.Errors) Error(e.ToString());\n    throw new InvalidOperationException(\"Invalid ocelot configuration, see errors above\");\n}","typeGuard":null,"tryCatchPattern":"try { await setter.SetAsync(fileConfiguration, ct); }\ncatch (ConfigurationRepositoryException ex)\n{\n    foreach (var e in ex.Errors) Error($\"Config error: {e}\");\n    throw;\n}","preventionTips":["Validate ocelot.json against the Ocelot schema before deployment","Log the Errors collection — it names each specific config problem","Re-validate configuration after Ocelot upgrades for breaking changes","Cover route/aggregates definitions with startup integration tests"],"tags":["configuration","validation","ocelot","repository"],"backgroundTag":"schema-validation-failed","analyzedSha":"d1f22d930430410bfd0233f5e9e4f92980cf7df0","analyzedAt":"2026-09-12T13:50:06.067Z","contentChangedAt":"2026-09-12T13:50:06.067Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}