# Buggy code
def __call__(self, result):
    from msrest.pipeline import ClientRawResponse

    if isinstance(result, poller_classes()):
        # most deployment operations return a poller
        result = super(DeploymentOutputLongRunningOperation, self).__call__(result)
        outputs = result.properties.outputs
        return {key: val["value"] for key, val in outputs.items()} if outputs else {}
    if isinstance(result, ClientRawResponse):
        # --no-wait returns a ClientRawResponse
        return None

    # --validate returns a 'normal' response
    return result


# Traceback (IndexError)
$ az vm extension image list --latest -l westcentralus -o tsv
The command failed with an unexpected error. Here is the traceback:

list index out of range
Traceback (most recent call last):
File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 206, in invoke
cmd_result = self.invocation.execute(args)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 560, in execute
raise ex
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 618, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 611, in _run_job
six.reraise(*sys.exc_info())
File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise
raise value
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 588, in _run_job
result = cmd_copy(params)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 297, in __call__
return self.handler(*args, **kwargs)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 461, in default_command_handler
return op(**command_args)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/vm/custom.py", line 1272, in list_vm_extension_images
cmd.cli_ctx, publisher_name, name, version, image_location, latest)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/vm/_actions.py", line 155, in load_extension_images_thru_services
t.result()  # don't use the result but expose exceptions from the threads
File "/opt/az/lib/python3.6/concurrent/futures/_base.py", line 425, in result
return self.__get_result()
File "/opt/az/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception
File "/opt/az/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/vm/_actions.py", line 137, in _load_extension_images_from_publisher
'version': versions[0].name})
IndexError: list index out of range

# Fixed code
def __call__(self, result):
    from msrest.pipeline import ClientRawResponse

    if isinstance(result, poller_classes()):
        # most deployment operations return a poller
        result = super(DeploymentOutputLongRunningOperation, self).__call__(result)
        outputs = None
        try:
            outputs = result.properties.outputs
        except AttributeError:  # super.__call__ might return a ClientRawResponse
            pass
        return {key: val["value"] for key, val in outputs.items()} if outputs else {}
    if isinstance(result, ClientRawResponse):
        # --no-wait returns a ClientRawResponse
        return {}

    # --validate returns a 'normal' response
    return result