loadConfigMap function

YamlMap loadConfigMap(
  1. String content, {
  2. required String file,
})

Loads content as a YAML mapping. Throws a ConfigException when it is invalid YAML, empty, or not a mapping.

Implementation

YamlMap loadConfigMap(String content, {required String file}) {
  final Object? document;
  try {
    document = loadYaml(content, sourceUrl: Uri.file(file));
  } on YamlException catch (e) {
    throw ConfigException(
      e.message,
      span: e.span == null
          ? null
          : SourceSpanLike(e.span!.start.line, e.span!.start.column),
      file: file,
    );
  }
  if (document == null) {
    throw ConfigException(
      'The file is empty. It needs at least a "version" key.',
      file: file,
    );
  }
  if (document is! YamlMap) {
    throw ConfigException(
      'Expected a mapping of keys to values at the top level.',
      file: file,
    );
  }
  return document;
}