{"action":"created","issue":{"url":"https://api.github.com/repos/saltstack/salt/issues/29732","labels_url":"https://api.github.com/repos/saltstack/salt/issues/29732/labels{/name}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/29732/comments","events_url":"https://api.github.com/repos/saltstack/salt/issues/29732/events","html_url":"https://github.com/saltstack/salt/pull/29732","id":122410197,"number":29732,"title":"Improve error reporting in pkg states","user":{"login":"terminalmage","id":328598,"avatar_url":"https://avatars.githubusercontent.com/u/328598?v=3","gravatar_id":"","url":"https://api.github.com/users/terminalmage","html_url":"https://github.com/terminalmage","followers_url":"https://api.github.com/users/terminalmage/followers","following_url":"https://api.github.com/users/terminalmage/following{/other_user}","gists_url":"https://api.github.com/users/terminalmage/gists{/gist_id}","starred_url":"https://api.github.com/users/terminalmage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terminalmage/subscriptions","organizations_url":"https://api.github.com/users/terminalmage/orgs","repos_url":"https://api.github.com/users/terminalmage/repos","events_url":"https://api.github.com/users/terminalmage/events{/privacy}","received_events_url":"https://api.github.com/users/terminalmage/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/saltstack/salt/labels/Awesome","name":"Awesome","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-16T01:57:52Z","updated_at":"2015-12-16T16:38:50Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/saltstack/salt/pulls/29732","html_url":"https://github.com/saltstack/salt/pull/29732","diff_url":"https://github.com/saltstack/salt/pull/29732.diff","patch_url":"https://github.com/saltstack/salt/pull/29732.patch"},"body":"This pull request modifies the ``CommandExecutionError`` exception, adding an\r\noptional parameter ``info`` via which additional information about the failure\r\ncan be passed. If present, this value will be passed through the nested\r\noutputter and added to the CLI return data. This allows us to report on partial\r\nchanges while still raising an exception.\r\n\r\n```python\r\nif errors:\r\n    raise CommandExecutionError(\r\n        'Failed to do foo and/or bar',\r\n        info={'errors': errors, 'changes': changes}\r\n    )\r\n```\r\n\r\nThis would result in the information returned to the master looking something\r\nlike this:\r\n\r\n```\r\nmyminion:\r\n    ERROR: Failed to do foo and/or bar. Additional info follows:\r\n\r\n    changes:\r\n        ----------\r\n        baz:\r\n            ----------\r\n            old:\r\n                123\r\n            new:\r\n                456\r\n    errors:\r\n        - foo failed with return code 1\r\n        - bar failed with return code 127\r\n```\r\n\r\n3 new attributes have been added to all CommandExecutionError instances.\r\nAssuming a CommandExecutionError instance named ``exc``, these would be:\r\n\r\n* ``exc.error`` - The string passed as the first postional parameter when\r\n  raising the error. This is equivalent to what used to be available as\r\n  ``exc.strerror``, since this attribute now contains the additional\r\n  information passed through the nested outputter. Note that if no ``info``\r\n  param is passed, ``exc.error`` and ``exc.strerror`` will both contain the\r\n  same information.\r\n\r\n* ``exc.info`` - The data structure passed as the newly-added ``info`` param\r\n  when raising the exception.\r\n\r\n* ``exc.strerror_without_changes`` - One useful application of this new\r\n  functionality in ``CommandExecutionError`` is to use it to funnel partial\r\n  changes in a failed state back up to the state function via try/except.\r\n  However, when the ``info`` dict contains a ``changes`` parameter, this\r\n  results in ``exc.strerror`` containing the changes. However, we want those\r\n  changes to be in the ``changes`` key in the state return data, and having\r\n  them in the comment for the state would be redundant as we'd get the changes\r\n  displayed twice in the return data. Hence this attribute, which contains the\r\n  nested output of the ``info`` dict like ``exc.strerror``, minus the\r\n  ``changes`` key. If ``exc.info`` contains just a ``changes`` key, then\r\n  ``exc.strerror_without_changes`` will be the same as ``exc.error`` (that is,\r\n  the error string passed when raising the exception).\r\n\r\nThe ``info`` param for the this exception does not need to be a dictionary, it\r\ncan be a list or string or int or float, anything that can be displayed using\r\nthe nested outputter. If it is not a dictionary, then\r\n``exc.strerror_without_changes`` will be identical to ``exc.strerror``.\r\n\r\nThe pkg states now leverage this new information available to\r\nCommandExecutionError instances to accurately report on partial changes made\r\nduring failed states. The package providers have in turn been modified to track\r\nerrors and report them via the new ``info`` param. This also has the benefit of\r\nmaking calls to ``pkg.install`` more informative, as in the past we would just\r\nbe returning an empty dictionary if a package installation failed. The onus was\r\non the user to check the minion logs for errors. Now, these errors will be\r\nshown right there in the return data, which will make troubleshooting failed\r\n``pkg.install`` calls much more convenient."},"comment":{"url":"https://api.github.com/repos/saltstack/salt/issues/comments/165169264","html_url":"https://github.com/saltstack/salt/pull/29732#issuecomment-165169264","issue_url":"https://api.github.com/repos/saltstack/salt/issues/29732","id":165169264,"user":{"login":"terminalmage","id":328598,"avatar_url":"https://avatars.githubusercontent.com/u/328598?v=3","gravatar_id":"","url":"https://api.github.com/users/terminalmage","html_url":"https://github.com/terminalmage","followers_url":"https://api.github.com/users/terminalmage/followers","following_url":"https://api.github.com/users/terminalmage/following{/other_user}","gists_url":"https://api.github.com/users/terminalmage/gists{/gist_id}","starred_url":"https://api.github.com/users/terminalmage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terminalmage/subscriptions","organizations_url":"https://api.github.com/users/terminalmage/orgs","repos_url":"https://api.github.com/users/terminalmage/repos","events_url":"https://api.github.com/users/terminalmage/events{/privacy}","received_events_url":"https://api.github.com/users/terminalmage/received_events","type":"User","site_admin":false},"created_at":"2015-12-16T16:38:50Z","updated_at":"2015-12-16T16:38:50Z","body":"Looks like some of the mocked references to ``CommandExecutionError`` might need to be updated. Taking a closer look now."}}