Skip to content

Bug: Non-existent runners folder in extracted zip causes failure in migrate.py #588

@gpsinghsandhu

Description

@gpsinghsandhu

This issue happened when extracting our customised script server zip where the zip didn't include the empty runners directory. This led to the following error:

Traceback (most recent call last):
File "path/to/script-server/./launcher.py", line 11, in
main.main()
File "path/to/script-server/script-server/src/main.py", line 79, in main
migrations.migrate.migrate(TEMP_FOLDER, CONFIG_FOLDER, SERVER_CONF_PATH, LOG_FOLDER)
File path/to/script-server/script-server/src/migrations/migrate.py", line 387, in migrate
migration_descriptor.callable(context)
File "path/to/script-server/script-server/src/migrations/migrate.py", line 269, in __migrate_bash_formatting_to_output_format
for (conf_file, json_object, content) in _load_runner_files(context.conf_folder):
TypeError: 'NoneType' object is not iterable

This is happening since the following function in migrate.py is returning None in case of non-existent runners directory:

def _load_runner_files(conf_folder):
    runners_folder = os.path.join(conf_folder, 'runners')

    if not os.path.exists(runners_folder):
        return

    conf_files = [os.path.join(runners_folder, file)
                  for file in os.listdir(runners_folder)
                  if file.lower().endswith('.json')]

    result = []

    for conf_file in conf_files:
        content = file_utils.read_file(conf_file)
        try:
            json_object = custom_json.loads(content, object_pairs_hook=OrderedDict)
            result.append((conf_file, json_object, content))
        except Exception:
            LOGGER.exception('Failed to load file for migration: ' + conf_file)
            continue

    return result

Submitting a PR for this soon.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions