def format_localrunner_result(result, do_serialize=True):
    output = format_possible_failure_result(result)
    # Add in various properties if they have values
    stdout = result.get('stdout', None)
    if stdout:
        try:
            output['stdout'] = stdout.strip()
        except __HOLE__:
            output['stdout'] = stdout
    stderr = result.get('stderr', None)
    if stderr:
        output['stderr'] = stderr.strip()
    return_code = result.get('return_code', 0)
    if return_code != 0:
        output['return_code'] = return_code
    error = result.get('error', None)
    if error:
        output['error'] = error

    return _serialize(output) if do_serialize else output
dataset/ETHPy150Open StackStorm/st2contrib/packs/hubot/actions/post_result.py/format_localrunner_result