# Buggy code
def execute_image(args):
    """Execution path for container images"""
    logger.debug("Starting analysis...")
    image_string = extract_image(args)
    # If the image has been extracted, load the metadata
    if image_string:
        full_image = cimage.load_full_image(image_string)
        # check if the image was loaded successfully
        if full_image.origins.is_empty():
            # Add an image origin here
            full_image.origins.add_notice_origin(
                formats.docker_image.format(imagetag=image_string)
            )
            # Set up for analysis
            setup(full_image)
            # analyze image
            cimage.analyze(full_image, args.redo, args.driver, args.extend)
            # report out
            report.report_out(args, full_image)
            # clean up
            teardown(full_image)
        else:
            # we cannot load the full image
            logger.error("Cannot retrieve full image metadata")
    # cleanup
    if not args.keep_wd:
        prep.clean_image_tars(full_image)


# Traceback (AttributeError)
$ tern report -o output.txt -i fossid-nginx:2020.2
2020-11-11 08:35:17,611 - DEBUG - __main__ - Starting...
2020-11-11 08:35:17,611 - DEBUG - prep - Setting up...
2020-11-11 08:35:18,060 - DEBUG - run - Starting analysis...
2020-11-11 08:35:18,154 - DEBUG - docker_api - Checking if image "fossid-nginx:2020.2" is available on disk...
2020-11-11 08:35:18,162 - DEBUG - docker_api - Attempting to pull image "fossid-nginx:2020.2"
2020-11-11 08:35:19,691 - WARNING - docker_api - No such image: "fossid-nginx:2020.2"
Traceback (most recent call last):
File "/home/nisha/terndev/bin/tern", line 10, in <module>
sys.exit(main())
File "/home/nisha/terndev/tern/tern/__main__.py", line 192, in main
do_main(args)
File "/home/nisha/terndev/tern/tern/__main__.py", line 95, in do_main
crun.execute_image(args)
File "/home/nisha/terndev/tern/tern/analyze/default/container/run.py", line 73, in execute_image
image_string = extract_image(args)
File "/home/nisha/terndev/tern/tern/analyze/default/container/run.py", line 32, in extract_image
image_attrs = docker_api.dump_docker_image(args.docker_image)
File "/home/nisha/terndev/tern/tern/load/docker_api.py", line 200, in dump_docker_image
if extract_image(image):
File "/home/nisha/terndev/tern/tern/load/docker_api.py", line 74, in extract_image
result = image_obj.save(chunk_size=2097152, named=True)
AttributeError: 'NoneType' object has no attribute 'save'

# Fixed code
def execute_image(args):
    """Execution path for container images"""
    logger.debug("Starting analysis...")
    image_string = extract_image(args)
    # If the image has been extracted, load the metadata
    if image_string:
        full_image = cimage.load_full_image(image_string)
        # check if the image was loaded successfully
        if full_image.origins.is_empty():
            # Add an image origin here
            full_image.origins.add_notice_origin(
                formats.docker_image.format(imagetag=image_string)
            )
            # Set up for analysis
            setup(full_image)
            # analyze image
            cimage.analyze(full_image, args.redo, args.driver, args.extend)
            # report out
            report.report_out(args, full_image)
            # clean up
            teardown(full_image)
        else:
            # we cannot load the full image
            logger.error("Cannot retrieve full image metadata")
        if not args.keep_wd:
            prep.clean_image_tars(full_image)