{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/36848","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/36848/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/36848/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/36848/events","html_url":"https://github.com/ansible/ansible/issues/36848","id":301028365,"number":36848,"title":"Double extended error message in AnsibleParserError (triple in 2.4)","user":{"login":"diafour","id":1055474,"avatar_url":"https://avatars3.githubusercontent.com/u/1055474?v=4","gravatar_id":"","url":"https://api.github.com/users/diafour","html_url":"https://github.com/diafour","followers_url":"https://api.github.com/users/diafour/followers","following_url":"https://api.github.com/users/diafour/following{/other_user}","gists_url":"https://api.github.com/users/diafour/gists{/gist_id}","starred_url":"https://api.github.com/users/diafour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diafour/subscriptions","organizations_url":"https://api.github.com/users/diafour/orgs","repos_url":"https://api.github.com/users/diafour/repos","events_url":"https://api.github.com/users/diafour/events{/privacy}","received_events_url":"https://api.github.com/users/diafour/received_events","type":"User","site_admin":false},"labels":[{"id":562292166,"url":"https://api.github.com/repos/ansible/ansible/labels/affects_2.4","name":"affects_2.4","color":"ededed","default":false},{"id":785271699,"url":"https://api.github.com/repos/ansible/ansible/labels/bug","name":"bug","color":"fbca04","default":true},{"id":48276055,"url":"https://api.github.com/repos/ansible/ansible/labels/bug_report","name":"bug_report","color":"fbca04","default":false},{"id":383076471,"url":"https://api.github.com/repos/ansible/ansible/labels/python3","name":"python3","color":"fbca04","default":false},{"id":636352796,"url":"https://api.github.com/repos/ansible/ansible/labels/support:core","name":"support:core","color":"ededed","default":false}],"state":"open","locked":false,"assignee":{"login":"alikins","id":15162,"avatar_url":"https://avatars0.githubusercontent.com/u/15162?v=4","gravatar_id":"","url":"https://api.github.com/users/alikins","html_url":"https://github.com/alikins","followers_url":"https://api.github.com/users/alikins/followers","following_url":"https://api.github.com/users/alikins/following{/other_user}","gists_url":"https://api.github.com/users/alikins/gists{/gist_id}","starred_url":"https://api.github.com/users/alikins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alikins/subscriptions","organizations_url":"https://api.github.com/users/alikins/orgs","repos_url":"https://api.github.com/users/alikins/repos","events_url":"https://api.github.com/users/alikins/events{/privacy}","received_events_url":"https://api.github.com/users/alikins/received_events","type":"User","site_admin":false},"assignees":[{"login":"alikins","id":15162,"avatar_url":"https://avatars0.githubusercontent.com/u/15162?v=4","gravatar_id":"","url":"https://api.github.com/users/alikins","html_url":"https://github.com/alikins","followers_url":"https://api.github.com/users/alikins/followers","following_url":"https://api.github.com/users/alikins/following{/other_user}","gists_url":"https://api.github.com/users/alikins/gists{/gist_id}","starred_url":"https://api.github.com/users/alikins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alikins/subscriptions","organizations_url":"https://api.github.com/users/alikins/orgs","repos_url":"https://api.github.com/users/alikins/repos","events_url":"https://api.github.com/users/alikins/events{/privacy}","received_events_url":"https://api.github.com/users/alikins/received_events","type":"User","site_admin":false}],"milestone":null,"comments":5,"created_at":"2018-02-28T13:43:28Z","updated_at":"2018-03-01T17:06:43Z","closed_at":null,"author_association":"NONE","body":"<!---\r\nVerify first that your issue/request is not already reported on GitHub.\r\nAlso test if the latest release, and devel branch are affected too.\r\n-->\r\n\r\n##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### COMPONENT NAME\r\nAnsibleError, AnsibleParserError, Task#preprocess_data, ModuleArgsParser#parse\r\n\r\n##### ANSIBLE VERSION\r\n```\r\n2.4, 2.5, devel\r\n```\r\n\r\n##### CONFIGURATION\r\nNo special configuration, local connection.\r\n\r\nansible-playbook -c local -i localhost, playbook.yml\r\n\r\nplaybook.yml:\r\n```\r\n---\r\n- hosts: all\r\n  tasks:\r\n  - apk: msgfd\r\n```\r\n\r\n\r\n##### OS / ENVIRONMENT\r\nUbuntu 16.04, Python 3.5.2 (default, Nov 23 2017, 16:37:01) in virtualenv\r\n\r\n##### SUMMARY\r\n\r\n`ModuleArgsParser#parse` raises `AnsibleParserError` if something is wrong with tasks or their arguments. \r\n`AnsibleParserError#__init__` append extended error to the message.\r\nThen `Task#preprocess_data` wraps `AnsibleParserError` with new instance of `AnsibleParserError` and thus extended error is doubled in message.\r\n\r\nExtended error is printed 3 times in version 2.4. `devel` branch has merged PR https://github.com/ansible/ansible/pull/24468 and extended error is printed 2 times.\r\n\r\nMay be something wrong with this wrapping?\r\nhttps://github.com/ansible/ansible/blob/ebf971f931290a113f738f658d7a6e095994e120/lib/ansible/playbook/task.py#L183-L187\r\n\r\n##### STEPS TO REPRODUCE\r\n\r\nSimple test case that raises error about extra params from https://github.com/ansible/ansible/blob/ebf971f931290a113f738f658d7a6e095994e120/lib/ansible/parsing/mod_args.py#L303\r\n\r\n```yaml\r\n---\r\n- hosts: all\r\n  tasks:\r\n  - apk: msgfd\r\n```\r\n\r\nCreate file and run it localy for verification:\r\n```\r\n$ ansible-playbook -c local -i localhost, playbook.yml\r\n```\r\n\r\n##### EXPECTED RESULTS\r\n\r\nClean error message with offending lines:\r\n\r\n```\r\nERROR! this task 'apk' has extra params, which is only allowed in the following modules: command, win_command, shell, win_shell, script, include, include_vars, include_tasks, include_role, import_tasks, import_role, add_host, group_by, set_fact, raw, meta\r\n\r\nThe error appears to have been in '/home/diafour/Projects/dapp/ansible-test/debug-playbook.yml': line 6, column 7, but may\r\nbe elsewhere in the file depending on the exact syntax problem.\r\n\r\nThe offending line appears to be:\r\n\r\n  tasks:\r\n    - apk: msgfd\r\n      ^ here\r\n```\r\n\r\n##### ACTUAL RESULTS\r\n\r\n###### devel branch:\r\n\r\nDouble output\r\n\r\n```\r\nERROR! this task 'apk' has extra params, which is only allowed in the following modules: command, win_command, shell, win_shell, script, include, include_vars, include_tasks, include_role, import_tasks, import_role, add_host, group_by, set_fact, raw, meta\r\n\r\nThe error appears to have been in '/home/diafour/Projects/dapp/ansible-test/debug-playbook.yml': line 6, column 7, but may\r\nbe elsewhere in the file depending on the exact syntax problem.\r\n\r\nThe offending line appears to be:\r\n\r\n  tasks:\r\n    - apk: msgfd\r\n      ^ here\r\n\r\n\r\nThe error appears to have been in '/home/diafour/Projects/dapp/ansible-test/debug-playbook.yml': line 6, column 7, but may\r\nbe elsewhere in the file depending on the exact syntax problem.\r\n\r\nThe offending line appears to be:\r\n\r\n  tasks:\r\n    - apk: msgfd\r\n      ^ here\r\n\r\n```\r\n\r\n###### version 2.4 (git checkout stable-2.4)\r\n\r\nTriple output\r\n\r\n```\r\nERROR! this task 'apk' has extra params, which is only allowed in the following modules: command, win_command, shell, win_shell, script, include, include_vars, include_tasks, include_role, import_tasks, import_role, add_host, group_by, set_fact, raw, meta\r\n\r\nThe error appears to have been in '/home/diafour/Projects/dapp/ansible-test/debug-playbook.yml': line 6, column 7, but may\r\nbe elsewhere in the file depending on the exact syntax problem.\r\n\r\nThe offending line appears to be:\r\n\r\n  tasks:\r\n    - apk: msgfd\r\n      ^ here\r\n\r\n\r\nThe error appears to have been in '/home/diafour/Projects/dapp/ansible-test/debug-playbook.yml': line 6, column 7, but may\r\nbe elsewhere in the file depending on the exact syntax problem.\r\n\r\nThe offending line appears to be:\r\n\r\n  tasks:\r\n    - apk: msgfd\r\n      ^ here\r\n\r\nexception type: <class 'ansible.errors.AnsibleParserError'>\r\nexception: this task 'apk' has extra params, which is only allowed in the following modules: command, win_command, shell, win_shell, script, include, include_vars, include_tasks, include_role, import_tasks, import_role, add_host, group_by, set_fact, raw, meta\r\n\r\nThe error appears to have been in '/home/diafour/Projects/dapp/ansible-test/debug-playbook.yml': line 6, column 7, but may\r\nbe elsewhere in the file depending on the exact syntax problem.\r\n\r\nThe offending line appears to be:\r\n\r\n  tasks:\r\n    - apk: msgfd\r\n      ^ here\r\n\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/369660975","html_url":"https://github.com/ansible/ansible/issues/36848#issuecomment-369660975","issue_url":"https://api.github.com/repos/ansible/ansible/issues/36848","id":369660975,"user":{"login":"alikins","id":15162,"avatar_url":"https://avatars0.githubusercontent.com/u/15162?v=4","gravatar_id":"","url":"https://api.github.com/users/alikins","html_url":"https://github.com/alikins","followers_url":"https://api.github.com/users/alikins/followers","following_url":"https://api.github.com/users/alikins/following{/other_user}","gists_url":"https://api.github.com/users/alikins/gists{/gist_id}","starred_url":"https://api.github.com/users/alikins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alikins/subscriptions","organizations_url":"https://api.github.com/users/alikins/orgs","repos_url":"https://api.github.com/users/alikins/repos","events_url":"https://api.github.com/users/alikins/events{/privacy}","received_events_url":"https://api.github.com/users/alikins/received_events","type":"User","site_admin":false},"created_at":"2018-03-01T17:06:43Z","updated_at":"2018-03-01T17:06:43Z","author_association":"CONTRIBUTOR","body":"\r\nFor cases like:\r\n\r\nhttps://github.com/ansible/ansible/blob/devel/lib/ansible/playbook/task.py#L187\r\n\r\n... guess there is no particular reason to re raise a new AnsibleParserError in those cases.\r\n As far as I can tell,  we could either just do a plain (re) `raise`, or if we need to set/update the AnsibleParserError._obj we can do it the original Exception instance and (re) `raise`\r\n\r\n``` python\r\n\r\ntry:\r\n    whatever()\r\nexcept AnsibleParserError as e:\r\n    # if we don't need to add/change the AnsibleError._obj, just re raise\r\n    raise\r\n\r\ntry:\r\n    whatever(some_thing_related_to_some_yaml_object)\r\nexcept AnsibleParserError as e:\r\n    # if whatever() doesn't specify obj=some_yaml_obj when it raises AnsibleParserError()\r\n    # we can just set/update it here and re raise\r\n    e._obj = some_yaml_obj\r\n    raise\r\n\r\n```\r\n   "}}
{"actor":{"display_login":"alikins"}}