loadConfigFile function

YamlMap? loadConfigFile()

Attempts to load a buggy config file from the current directory.

Looks for buggy.yaml first, then buggy.yml as a fallback. Returns the parsed YamlMap, or null if no config file is found.

Throws a FormatException if the file exists but contains invalid YAML or is not a YAML map.

Implementation

YamlMap? loadConfigFile() {
  for (final filename in ['buggy.yaml', 'buggy.yml']) {
    final file = File(filename);
    if (file.existsSync()) {
      final content = file.readAsStringSync();
      final yaml = loadYaml(content);
      if (yaml is! YamlMap) {
        throw FormatException(
          '$filename must be a YAML map, got ${yaml.runtimeType}.',
        );
      }
      return yaml;
    }
  }
  return null;
}