Skip to content

Commit b312307

Browse files
authored
Not found errors raised by id_for use more specific error classes when they exist (#583)
1 parent 4e2880f commit b312307

File tree

6 files changed

+12
-5
lines changed

6 files changed

+12
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
### 3.1.1 (Next)
1+
### 3.2.0 (Next)
22

33
* [#581](https://github.com/slack-ruby/slack-ruby-client/pull/581): Migrate Danger to use danger-pr-comment workflow - [@dblock](https://github.com/dblock).
4+
* [#583](https://github.com/slack-ruby/slack-ruby-client/pull/583): Not found errors raised by id_for use more specific error classes when they exist - [@eizengan](https://github.com/eizengan).
45
* Your contribution here.
56

67
### 3.1.0 (2025/11/15)

UPGRADING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Upgrading Slack-Ruby-Client
22
===========================
33

4+
### Upgrading to >= 3.2.0
5+
6+
[#583](https://github.com/slack-ruby/slack-ruby-client/pull/583) modifies the error types raised when a nonexistent #channel-name or @user-handle is looked up. These will now raise `ChannelNotFound` and `UserNotFound` respectively, whereas they previously raised a `SlackError`. If your code relies on these types without accounting for inheritance, it will need to be migrated. Notably, `rescue SlackError` will continue to work as normal, since both error classes inherit from it.
7+
48
### Upgrading to >= 3.0.0
59

610
Support for the [RTM API](https://docs.slack.dev/tools/java-slack-sdk/guides/rtm/) has been removed in [#573](https://github.com/slack-ruby/slack-ruby-client/pull/573). By now you should have [migrated your app to granular permissions](https://code.dblock.org/2020/11/30/migrating-classic-slack-ruby-bots-to-granular-permissions.html), and you should lock your slack-ruby-client to 2.x for those bots. Next, to remove RTM components we found it more effective to just [write a new version of a bot](https://code.dblock.org/2024/06/30/writing-a-channel-slack-bot.html) and avoid a complex migration.

lib/slack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# frozen_string_literal: true
22
module Slack
3-
VERSION = '3.1.1'
3+
VERSION = '3.2.0'
44
end

lib/slack/web/api/mixins/ids.id.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def id_for(key:, name:, prefix:, enum_method:, list_method:, options: {})
1515
end
1616
end
1717

18-
raise Slack::Web::Api::Errors::SlackError, "#{key}_not_found"
18+
error_message = "#{key}_not_found"
19+
error_class = Slack::Web::Api::Errors::ERROR_CLASSES[error_message] || Slack::Web::Api::Errors::SlackError
20+
raise error_class, error_message
1921
end
2022
end
2123
end

spec/slack/web/api/mixins/conversations_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
it 'fails with an exception' do
6161
expect { conversations.conversations_id(channel: '#invalid') }.to(
62-
raise_error(Slack::Web::Api::Errors::SlackError, 'channel_not_found')
62+
raise_error(Slack::Web::Api::Errors::ChannelNotFound, 'channel_not_found')
6363
)
6464
end
6565

spec/slack/web/api/mixins/users_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
it 'fails with an exception' do
4848
expect { users.users_id(user: '@foo') }.to(
49-
raise_error(Slack::Web::Api::Errors::SlackError, 'user_not_found')
49+
raise_error(Slack::Web::Api::Errors::UserNotFound, 'user_not_found')
5050
)
5151
end
5252

0 commit comments

Comments
 (0)