# Buggy code
def run_command(jboss_config, command, fail_on_error=True):
    """
    Execute a command against jboss instance through the CLI interface.

    jboss_config
           Configuration dictionary with properties specified above.
    command
           Command to execute against jboss instance
    fail_on_error (default=True)
           Is true, raise CommandExecutionError exception if execution fails.
           If false, 'success' property of the returned dictionary is set to False

    CLI Example:

    .. code-block:: bash

        salt '*' jboss7_cli.run_command '{"cli_path": "integration.modules.sysmod.SysModuleTest.test_valid_docs", "controller": "10.11.12.13:9999", "cli_user": "jbossadm", "cli_password": "jbossadm"}' my_command
    """
    cli_command_result = __call_cli(jboss_config, command)

    if cli_command_result["retcode"] == 0:
        cli_command_result["success"] = True
    else:
        if fail_on_error:
            raise CommandExecutionError(
                """Command execution failed, return code={retcode}, stdout='{stdout}', stderr='{stderr}' """.format(
                    **cli_command_result
                )
            )
        else:
            cli_command_result["success"] = False

    return cli_command_result


# Traceback (AttributeError)
ID: CMDataSource
Function: jboss7.datasource_exists
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/state.py", line 1561, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/site-packages/salt/states/jboss7.py", line 129, in datasource_exists
ds_result = __salt__['jboss7.read_datasource'](jboss_config=jboss_config, name=name)
File "/usr/lib/python2.7/site-packages/salt/modules/jboss7.py", line 243, in read_datasource
return __read_datasource(jboss_config, name)
File "/usr/lib/python2.7/site-packages/salt/modules/jboss7.py", line 332, in __read_datasource
operation_result = __salt__['jboss7_cli.run_operation'](jboss_config, operation)
File "/usr/lib/python2.7/site-packages/salt/modules/jboss7_cli.py", line 114, in run_operation
cli_result['err_code'] = match.group(1)
AttributeError: 'NoneType' object has no attribute 'group'
Started: 12:27:24.778509
Duration: 1724.338 ms
Changes:

# Fixed code
def run_command(jboss_config, command, fail_on_error=True):
    """
    Execute a command against jboss instance through the CLI interface.

    jboss_config
           Configuration dictionary with properties specified above.
    command
           Command to execute against jboss instance
    fail_on_error (default=True)
           Is true, raise CommandExecutionError exception if execution fails.
           If false, 'success' property of the returned dictionary is set to False

    CLI Example:

    .. code-block:: bash

        salt '*' jboss7_cli.run_command '{"cli_path": "integration.modules.sysmod.SysModuleTest.test_valid_docs", "controller": "10.11.12.13:9999", "cli_user": "jbossadm", "cli_password": "jbossadm"}' my_command
    """
    cli_command_result = _call_cli(jboss_config, command)

    if cli_command_result["retcode"] == 0:
        cli_command_result["success"] = True
    else:
        if fail_on_error:
            raise CommandExecutionError(
                """Command execution failed, return code={retcode}, stdout='{stdout}', stderr='{stderr}' """.format(
                    **cli_command_result
                )
            )
        else:
            cli_command_result["success"] = False

    return cli_command_result