Fix valid_provider! raising ArgumentError instead of InvalidConfigError#964
Merged
dersam merged 1 commit intoJun 22, 2026
Conversation
## Problem Both `Chat::Config#valid_provider!` and `Agent::Config#valid_provider!` raise `ArgumentError` when given an invalid provider name, despite their doc comments explicitly promising `InvalidConfigError`: ```ruby # Note: this method will return the name of a valid provider # or raise an `InvalidConfigError`. def valid_provider! # ... raise ArgumentError, "'...' is not a valid provider..." end ``` This means any caller writing `rescue InvalidConfigError` — following the documented contract — will not catch invalid provider errors. The exception escapes as an unhandled `ArgumentError` instead of flowing through the `ConfigError` hierarchy like every other config validation. ## Fix Changed both methods to raise `InvalidConfigError` (which they inherit from `Cog::Config` via the class hierarchy). This is consistent with: - `Chat::Config#valid_api_key!` (line 124), which already raises `InvalidConfigError` for missing API keys - `Map::Config#valid_parallel!` (line 89) - `Config#working_directory` (lines 297–298) - All `Config#validate!` overrides across the cog tree Updated the corresponding tests in both `chat/config_test.rb` and `agent/config_test.rb` to assert `Cog::Config::InvalidConfigError` instead of `ArgumentError`. ## Files changed - `lib/roast/cogs/chat/config.rb` — line 70 - `lib/roast/cogs/agent/config.rb` — line 54 - `test/roast/cogs/chat/config_test.rb` — line 53 - `test/roast/cogs/agent/config_test.rb` — line 34
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Jun 19, 2026
dersam
approved these changes
Jun 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
Both
Chat::Config#valid_provider!andAgent::Config#valid_provider!raise
ArgumentErrorwhen given an invalid provider name, despite theirdoc comments explicitly promising
InvalidConfigError:This means any caller writing
rescue InvalidConfigError— followingthe documented contract — will not catch invalid provider errors. The
exception escapes as an unhandled
ArgumentErrorinstead of flowingthrough the
ConfigErrorhierarchy like every other config validation.Fix
Changed both methods to raise
InvalidConfigError(which they inheritfrom
Cog::Configvia the class hierarchy). This is consistent with:Chat::Config#valid_api_key!(line 124), which already raisesInvalidConfigErrorfor missing API keysMap::Config#valid_parallel!(line 89)Config#working_directory(lines 297–298)Config#validate!overrides across the cog treeUpdated the corresponding tests in both
chat/config_test.rbandagent/config_test.rbto assertCog::Config::InvalidConfigErrorinstead of
ArgumentError.