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

Merged
merged 6 commits into from
Dec 2, 2024

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 :)

@felixfontein
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@sivel
Copy link
Contributor

sivel commented Dec 2, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Dec 2, 2024
@sivel sivel closed this Dec 2, 2024
@sivel sivel reopened this Dec 2, 2024
@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Dec 2, 2024
@felixfontein felixfontein merged commit f2dbe08 into ansible-collections:main Dec 2, 2024
253 of 258 checks passed
Copy link

patchback bot commented Dec 2, 2024

Backport to stable-9: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-9/f2dbe08d0e86dcbcb78bba52d9d19d5094089cbb/pr-9198

Backported as #9211

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Dec 2, 2024
patchback bot pushed a commit that referenced this pull request Dec 2, 2024
* Fails if slack api return is not ok

* add changelog

* show all error

* add doc

* Update plugins/modules/slack.py

Co-authored-by: Felix Fontein <[email protected]>

* Update changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit f2dbe08)
Copy link

patchback bot commented Dec 2, 2024

Backport to stable-10: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-10/f2dbe08d0e86dcbcb78bba52d9d19d5094089cbb/pr-9198

Backported as #9212

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Dec 2, 2024
* Fails if slack api return is not ok

* add changelog

* show all error

* add doc

* Update plugins/modules/slack.py

Co-authored-by: Felix Fontein <[email protected]>

* Update changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit f2dbe08)
@felixfontein
Copy link
Collaborator

@Aohzan thanks for your contribution!

felixfontein pushed a commit that referenced this pull request Dec 2, 2024
…not OK with error message (#9211)

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

* Fails if slack api return is not ok

* add changelog

* show all error

* add doc

* Update plugins/modules/slack.py

Co-authored-by: Felix Fontein <[email protected]>

* Update changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit f2dbe08)

Co-authored-by: Matthieu Bourgain <[email protected]>
felixfontein pushed a commit that referenced this pull request Dec 2, 2024
… not OK with error message (#9212)

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

* Fails if slack api return is not ok

* add changelog

* show all error

* add doc

* Update plugins/modules/slack.py

Co-authored-by: Felix Fontein <[email protected]>

* Update changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit f2dbe08)

Co-authored-by: Matthieu Bourgain <[email protected]>
@Aohzan Aohzan deleted the patch-1 branch December 3, 2024 07:46
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 module module plugins plugin (any type) traceback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants