# Buggy code
def get_commands_from_metadata(image_layer):
    """Given the image layer object, get the list of command objects that
    created the layer. Return an empty list of we can't do that"""
    # set up notice origin for the layer
    origin_layer = "Layer {}".format(image_layer.layer_index)
    # check if there is a key containing the script that created the layer
    if image_layer.created_by:
        command_line = fltr.get_run_command(image_layer.created_by)
        if command_line:
            command_list, msg = fltr.filter_install_commands(
                general.clean_command(command_line)
            )
            if msg:
                image_layer.origins.add_notice_to_origins(
                    origin_layer, Notice(msg, "warning")
                )
            return command_list
    image_layer.origins.add_notice_to_origins(
        origin_layer,
        Notice(errors.unknown_content.format(files=command_line), "warning"),
    )
    return []


# Traceback (UnboundLocalError)
Traceback (most recent call last):
File "/usr/local/bin/tern", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/dist-packages/tern/__main__.py", line 192, in main
do_main(args)
File "/usr/local/lib/python3.7/dist-packages/tern/__main__.py", line 95, in do_main
crun.execute_image(args)
File "/usr/local/lib/python3.7/dist-packages/tern/analyze/default/container/run.py", line 85, in execute_image
cimage.analyze(full_image, args.redo, args.driver, args.extend)
File "/usr/local/lib/python3.7/dist-packages/tern/analyze/default/container/image.py", line 74, in analyze
default_analyze(image_obj, redo, driver)
File "/usr/local/lib/python3.7/dist-packages/tern/analyze/default/container/image.py", line 64, in default_analyze
image_obj, shell, master_list, redo, driver)
File "/usr/local/lib/python3.7/dist-packages/tern/analyze/default/container/multi_layer.py", line 99, in analyze_subsequent_layers
fresh_analysis(image_obj, curr_layer, shell, driver, envs)
File "/usr/local/lib/python3.7/dist-packages/tern/analyze/default/container/multi_layer.py", line 52, in fresh_analysis
image_obj.layers[curr_layer])
File "/usr/local/lib/python3.7/dist-packages/tern/analyze/default/default_common.py", line 119, in get_commands_from_metadata
files=command_line), 'warning'))
UnboundLocalError: local variable 'command_line' referenced before assignment

# Fixed code
def get_commands_from_metadata(image_layer):
    """Given the image layer object, get the list of command objects that
    created the layer. Return an empty list of we can't do that"""
    # set up notice origin for the layer
    origin_layer = "Layer {}".format(image_layer.layer_index)
    # check if there is a key containing the script that created the layer
    if image_layer.created_by:
        command_line = fltr.get_run_command(image_layer.created_by)
        if command_line:
            command_list, msg = fltr.filter_install_commands(
                general.clean_command(command_line)
            )
            if msg:
                image_layer.origins.add_notice_to_origins(
                    origin_layer, Notice(msg, "warning")
                )
            return command_list
    image_layer.origins.add_notice_to_origins(
        origin_layer, Notice(errors.no_layer_created_by, "warning")
    )
    return []