# Buggy code
def from_json(cls, json_info, guess=False):
    from ..util import parse_date

    info = {key: val for key, val in json_info.items() if key in cls.field_names()}
    if guess:
        keys = info.keys()
        if "start_ts" not in keys:
            info["start_ts"], info["end_ts"] = cls.guess_ts(json_info)
        else:
            info["start_ts"] = parse_date(info["start_ts"])
            info["end_ts"] = parse_date(info["end_ts"])
        if "pwd" not in keys:
            info["pwd"] = str(
                Path(OUTPUT_DIR) / ARCHIVE_DIR_NAME / json_info["timestamp"]
            )
        if "cmd_version" not in keys:
            info["cmd_version"] = "Undefined"
        if "cmd" not in keys:
            info["cmd"] = []
    else:
        info["start_ts"] = parse_date(info["start_ts"])
        info["end_ts"] = parse_date(info["end_ts"])
        info["cmd_version"] = info.get("cmd_version")
    return cls(**info)


# Traceback (KeyError)
Traceback (most recent call last):
File "/home/USERNAME/.local/bin/archivebox", line 8, in <module>
sys.exit(main())
File "/home/USERNAME/.local/lib/python3.7/site-packages/archivebox/cli/__init__.py", line 126, in main
pwd=pwd or OUTPUT_DIR,
File "/home/USERNAME/.local/lib/python3.7/site-packages/archivebox/cli/__init__.py", line 62, in run_subcommand
module.main(args=subcommand_args, stdin=stdin, pwd=pwd)    # type: ignore
File "/home/USERNAME/.local/lib/python3.7/site-packages/archivebox/cli/archivebox_init.py", line 34, in main
out_dir=pwd or OUTPUT_DIR,
File "/home/USERNAME/.local/lib/python3.7/site-packages/archivebox/util.py", line 108, in typechecked_function
return func(*args, **kwargs)
File "/home/USERNAME/.local/lib/python3.7/site-packages/archivebox/main.py", line 316, in init
for link in load_main_index(out_dir=out_dir, warn=False)
File "/home/USERNAME/.local/lib/python3.7/site-packages/archivebox/util.py", line 108, in typechecked_function
return func(*args, **kwargs)
File "/home/USERNAME/.local/lib/python3.7/site-packages/archivebox/index/__init__.py", line 250, in load_main_index
all_links = list(parse_json_main_index(out_dir))
File "/home/USERNAME/.local/lib/python3.7/site-packages/archivebox/index/json.py", line 52, in parse_json_main_index
yield Link.from_json(link_json)
File "/home/USERNAME/.local/lib/python3.7/site-packages/archivebox/index/schema.py", line 203, in from_json
cast_result = ArchiveResult.from_json(json_result)
File "/home/USERNAME/.local/lib/python3.7/site-packages/archivebox/index/schema.py", line 62, in from_json
info['start_ts'] = parse_date(info['start_ts'])
KeyError: 'start_ts'

# Fixed code
def from_json(cls, json_info, guess=False):
    from ..util import parse_date

    info = {key: val for key, val in json_info.items() if key in cls.field_names()}
    if guess:
        keys = info.keys()
        if "start_ts" not in keys:
            info["start_ts"], info["end_ts"] = cls.guess_ts(json_info)
        else:
            info["start_ts"] = parse_date(info["start_ts"])
            info["end_ts"] = parse_date(info["end_ts"])
        if "pwd" not in keys:
            info["pwd"] = str(
                Path(OUTPUT_DIR) / ARCHIVE_DIR_NAME / json_info["timestamp"]
            )
        if "cmd_version" not in keys:
            info["cmd_version"] = "Undefined"
        if "cmd" not in keys:
            info["cmd"] = []
    else:
        info["start_ts"] = parse_date(info["start_ts"])
        info["end_ts"] = parse_date(info["end_ts"])
        info["cmd_version"] = info.get("cmd_version")
    if type(info["cmd"]) is str:
        info["cmd"] = [info["cmd"]]
    return cls(**info)