diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b1dc81f..742a36b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ -### 3.1.1 (Next) +### 3.2.0 (Next) * [#581](https://github.com/slack-ruby/slack-ruby-client/pull/581): Migrate Danger to use danger-pr-comment workflow - [@dblock](https://github.com/dblock). +* [#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). * Your contribution here. ### 3.1.0 (2025/11/15) diff --git a/UPGRADING.md b/UPGRADING.md index 94ecde42..9bc3cb19 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,6 +1,10 @@ Upgrading Slack-Ruby-Client =========================== +### Upgrading to >= 3.2.0 + +[#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. + ### Upgrading to >= 3.0.0 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. diff --git a/lib/slack/version.rb b/lib/slack/version.rb index 1295eae8..6746988c 100644 --- a/lib/slack/version.rb +++ b/lib/slack/version.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module Slack - VERSION = '3.1.1' + VERSION = '3.2.0' end diff --git a/lib/slack/web/api/mixins/ids.id.rb b/lib/slack/web/api/mixins/ids.id.rb index 40f8dd1d..867d4ffd 100644 --- a/lib/slack/web/api/mixins/ids.id.rb +++ b/lib/slack/web/api/mixins/ids.id.rb @@ -15,7 +15,9 @@ def id_for(key:, name:, prefix:, enum_method:, list_method:, options: {}) end end - raise Slack::Web::Api::Errors::SlackError, "#{key}_not_found" + error_message = "#{key}_not_found" + error_class = Slack::Web::Api::Errors::ERROR_CLASSES[error_message] || Slack::Web::Api::Errors::SlackError + raise error_class, error_message end end end diff --git a/spec/slack/web/api/mixins/conversations_spec.rb b/spec/slack/web/api/mixins/conversations_spec.rb index e7fd95b2..87704239 100644 --- a/spec/slack/web/api/mixins/conversations_spec.rb +++ b/spec/slack/web/api/mixins/conversations_spec.rb @@ -59,7 +59,7 @@ it 'fails with an exception' do expect { conversations.conversations_id(channel: '#invalid') }.to( - raise_error(Slack::Web::Api::Errors::SlackError, 'channel_not_found') + raise_error(Slack::Web::Api::Errors::ChannelNotFound, 'channel_not_found') ) end diff --git a/spec/slack/web/api/mixins/users_spec.rb b/spec/slack/web/api/mixins/users_spec.rb index 5c175263..426eccba 100644 --- a/spec/slack/web/api/mixins/users_spec.rb +++ b/spec/slack/web/api/mixins/users_spec.rb @@ -46,7 +46,7 @@ it 'fails with an exception' do expect { users.users_id(user: '@foo') }.to( - raise_error(Slack::Web::Api::Errors::SlackError, 'user_not_found') + raise_error(Slack::Web::Api::Errors::UserNotFound, 'user_not_found') ) end