aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/slack-config.el14
-rw-r--r--tests/test-slack-config-reactions.el5
2 files changed, 12 insertions, 7 deletions
diff --git a/modules/slack-config.el b/modules/slack-config.el
index 14d15ecf..3e9ae283 100644
--- a/modules/slack-config.el
+++ b/modules/slack-config.el
@@ -171,14 +171,14 @@ so the Slack buffer stays usable."
reaction)))
(defun cj/slack-message-add-reaction ()
- "Add a reaction to the current Slack message using a curated shortlist."
+ "Add a reaction to the current Slack message using a curated shortlist.
+Errors if called outside a Slack message buffer."
(interactive)
- (when-let* ((buf slack-current-buffer)
- (team (slack-buffer-team buf))
- (reaction (cj/slack-select-reaction team)))
- (slack-buffer-add-reaction-to-message buf
- reaction
- (slack-get-ts))))
+ (let ((buf (or slack-current-buffer
+ (user-error "Not in a Slack buffer"))))
+ (when-let* ((team (slack-buffer-team buf))
+ (reaction (cj/slack-select-reaction team)))
+ (slack-buffer-add-reaction-to-message buf reaction (slack-get-ts)))))
(with-eval-after-load 'slack-buffer
(advice-add 'slack-reaction-echo-description
diff --git a/tests/test-slack-config-reactions.el b/tests/test-slack-config-reactions.el
index a5755a49..491b8147 100644
--- a/tests/test-slack-config-reactions.el
+++ b/tests/test-slack-config-reactions.el
@@ -87,5 +87,10 @@
(cj/slack-message-add-reaction)
(should (equal called '(:buffer "pray" "123.456"))))))
+(ert-deftest test-slack-config-message-add-reaction-errors-outside-slack-buffer ()
+ "Error: invoking the reaction command outside a Slack buffer fails clearly."
+ (let ((slack-current-buffer nil))
+ (should-error (cj/slack-message-add-reaction) :type 'user-error)))
+
(provide 'test-slack-config-reactions)
;;; test-slack-config-reactions.el ends here