Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail if Slack API response is not OK with error message #9198

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Aohzan
Copy link
Contributor

@Aohzan Aohzan commented Nov 26, 2024

SUMMARY

Currently, when I try to edit a slack message, the module call the get_slack_message function and fails on if len(data['messages']) < 1: because messages is not return by Slack API.
So this PR return to ansible the result of the request to show the real error to the user.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

community.general.slack

ADDITIONAL INFORMATION
  community.general.slack:
    token: "xxx"
    channel: "{{ previous_task.channel }}"
    msg: "edit message"
    message_id: "{{ previous_task.ts }}"
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'messages'
fatal: [mymachine -> localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/me/.ansible/tmp/ansible-tmp-1732624276.3207872-172112-264078090362199/AnsiballZ_slack.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/me/.ansible/tmp/ansible-tmp-1732624276.3207872-172112-264078090362199/AnsiballZ_slack.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/me/.ansible/tmp/ansible-tmp-1732624276.3207872-172112-264078090362199/AnsiballZ_slack.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.slack', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.slack', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_community.general.slack_payload_reagkbux/ansible_community.general.slack_payload.zip/ansible_collections/community/general/plugins/modules/slack.py\", line 520, in <module>\n  File \"/tmp/ansible_community.general.slack_payload_reagkbux/ansible_community.general.slack_payload.zip/ansible_collections/community/general/plugins/modules/slack.py\", line 488, in main\n  File \"/tmp/ansible_community.general.slack_payload_reagkbux/ansible_community.general.slack_payload.zip/ansible_collections/community/general/plugins/modules/slack.py\", line 394, in get_slack_message\nKeyError: 'messages'\n", "module_stdout": "", "msg": "MODULE FAILURE: No start of json char found\nSee stdout/stderr for the exact error", "rc": 1}

become

fatal: [mymachine -> localhost]: FAILED! => {"changed": false, "msg": "failed to get slack message: {'ok': False, 'error': 'missing_scope', 'needed': 'channels:history,groups:history,mpim:history,im:history', 'provided': 'chat:write,chat:write.customize,incoming-webhook,chat:write.public'}"}

@Aohzan Aohzan changed the title Fails if slack api return is not ok Fail if Slack API response is not OK with error message Nov 26, 2024
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) traceback labels Nov 26, 2024
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-9 Automatically create a backport for the stable-9 branch backport-10 Automatically create a backport for the stable-10 branch labels Nov 26, 2024
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

plugins/modules/slack.py Outdated Show resolved Hide resolved
Aohzan and others added 2 commits November 28, 2024 21:37
@felixfontein
Copy link
Collaborator

I'll merge this on the weekend if nobody objects, and assuming that CI passes. Right now there seems to be an AZP problem, I'll try to restart CI tomorrow, hopefully AZP fixed the problem by then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-9 Automatically create a backport for the stable-9 branch backport-10 Automatically create a backport for the stable-10 branch bug This issue/PR relates to a bug check-before-release PR will be looked at again shortly before release and merged if possible. module module plugins plugin (any type) traceback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants