# Buggy code
def start(self):
    include_invalid = not self.valid_only
    runtimes = self.metadata_manager.get_all_metadata_summary(
        include_invalid=include_invalid
    )

    if not runtimes:
        print(
            "No metadata available for external runtimes at : '{}'".format(
                self.metadata_manager.get_metadata_location
            )
        )
        return

    if self.json_output:
        [
            print(
                "Runtime: {} {}\n{}".format(
                    rt.name,
                    "**INVALID**" if rt.reason and len(rt.reason) > 0 else "",
                    rt.to_json(),
                )
            )
            for rt in runtimes
        ]
    else:
        sorted_runtimes = sorted(runtimes, key=lambda runtime: runtime.name)
        # pad to width of longest runtime name
        max_name_len = 0
        max_resource_len = 0
        for runtime in sorted_runtimes:
            max_name_len = max(len(runtime.name), max_name_len)
            max_resource_len = max(len(runtime.resource), max_resource_len)

        print("Available metadata for external runtimes:")
        for runtime in sorted_runtimes:
            invalid = ""
            if runtime.reason and len(runtime.reason) > 0:
                invalid = "**INVALID** ({})".format(runtime.reason)
            print(
                "  %s  %s  %s"
                % (
                    runtime.name.ljust(max_name_len),
                    runtime.resource.ljust(max_resource_len),
                    invalid,
                )
            )


# Traceback (KeyError)
C:\Users\Administrator\Downloads>jupyter runtimes list
Traceback (most recent call last):
File "c:\programdata\anaconda3\envs\elyra\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\programdata\anaconda3\envs\elyra\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\ProgramData\Anaconda3\envs\elyra\Scripts\jupyter-runtimes.EXE\__main__.py", line 7, in <module>
File "c:\programdata\anaconda3\envs\elyra\lib\site-packages\traitlets\config\application.py", line 664, in launch_instance
app.start()
File "c:\programdata\anaconda3\envs\elyra\lib\site-packages\elyra\metadata\runtime.py", line 282, in start
return self.subapp.start()
File "c:\programdata\anaconda3\envs\elyra\lib\site-packages\elyra\metadata\runtime.py", line 67, in start
runtimes = self.metadata_manager.get_all_metadata_summary(include_invalid=include_invalid)
File "c:\programdata\anaconda3\envs\elyra\lib\site-packages\elyra\metadata\metadata.py", line 99, in get_all_metadata_summary
return self.metadata_store.get_all_metadata_summary(include_invalid=include_invalid)
File "c:\programdata\anaconda3\envs\elyra\lib\site-packages\elyra\metadata\metadata.py", line 178, in get_all_metadata_summary
metadata_list = self._load_metadata_resources(include_invalid=include_invalid)
File "c:\programdata\anaconda3\envs\elyra\lib\site-packages\elyra\metadata\metadata.py", line 291, in _load_metadata_resources
raise KeyError("Namespace '{}' was not found!".format(self.namespace))
KeyError: "Namespace 'runtimes' was not found!"

# Fixed code
def start(self):
    include_invalid = not self.valid_only
    try:
        runtimes = self.metadata_manager.get_all_metadata_summary(
            include_invalid=include_invalid
        )
    except KeyError:
        runtimes = None

    if not runtimes:
        print(
            "No metadata available for external runtimes at: '{}'".format(
                self.metadata_manager.get_metadata_location
            )
        )
        return

    if self.json_output:
        [
            print(
                "Runtime: {} {}\n{}".format(
                    rt.name,
                    "**INVALID**" if rt.reason and len(rt.reason) > 0 else "",
                    rt.to_json(),
                )
            )
            for rt in runtimes
        ]
    else:
        sorted_runtimes = sorted(runtimes, key=lambda runtime: runtime.name)
        # pad to width of longest runtime name
        max_name_len = 0
        max_resource_len = 0
        for runtime in sorted_runtimes:
            max_name_len = max(len(runtime.name), max_name_len)
            max_resource_len = max(len(runtime.resource), max_resource_len)

        print("Available metadata for external runtimes:")
        for runtime in sorted_runtimes:
            invalid = ""
            if runtime.reason and len(runtime.reason) > 0:
                invalid = "**INVALID** ({})".format(runtime.reason)
            print(
                "  %s  %s  %s"
                % (
                    runtime.name.ljust(max_name_len),
                    runtime.resource.ljust(max_resource_len),
                    invalid,
                )
            )