index.rst 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. .. _return-codes:
  2. ============
  3. Return Codes
  4. ============
  5. When the ``salt`` or ``salt-call`` CLI commands result in an error, the command
  6. will exit with a return code of **1**. Error cases consist of the following:
  7. 1. Errors are encountered while running :ref:`States
  8. <configuration-management>`, or any state returns a ``False`` result
  9. 2. Any exception is raised
  10. 3. In the case of remote-execution functions, when the return data is a
  11. :ref:`Python dictionary <typesmapping>` with a key named either ``result``
  12. or ``success``, which has a value of ``False``
  13. Retcode Passthrough
  14. ===================
  15. In addition to the cases listed above, if a state or remote-execution function
  16. sets a nonzero value in the ``retcode`` key of the :ref:`__context__
  17. <dunder-context>` dictionary, the command will exit with a return code of
  18. **1**. For those developing custom states and execution modules, using
  19. ``__context__['retcode']`` can be a useful way of signaling that an error has
  20. occurred:
  21. .. code-block:: python
  22. if something_went_wrong:
  23. __context__['retcode'] = 42
  24. This is actually how states signal that they have failed. Different cases
  25. result in different codes being set in the :ref:`__context__ <dunder-context>`
  26. dictionary:
  27. - **1** is set when any error is encountered in the state compiler (missing SLS
  28. file, etc.)
  29. - **2** is set when any state returns a ``False`` result
  30. - **5** is set when Pillar data fails to be compiled before running the
  31. state(s)
  32. When the ``--retcode-passthrough`` flag is used with ``salt-call``, then
  33. ``salt-call`` will exit with whichever retcode was set in the :ref:`__context__
  34. <dunder-context>` dictionary, rather than the default behavior which simply
  35. exits with **1** for any error condition.