read<T> method

T read<T>(
  1. ConfigPath path
)

Implementation

T read<T>(ConfigPath path) {
  final raw = _resolve(path.getFrom(_configMap), {path.toString()});
  if (raw == null) {
    if (null is T) {
      if (_diagnosedPaths.add(path.toString())) {
        final target = _diagnosisTarget(path);
        if (_findSimilarPath(target) case final suggestion?) {
          _warnAboutTypo(path, target, suggestion);
        }
      }
      return null as T;
    } else {
      throw ConfigPathException(
        path.toString(),
        suggestion: _findSimilarPath(_diagnosisTarget(path)),
      );
    }
  }

  try {
    return _codec.decodeTyped<T>(raw);
  } on CodecException catch (_) {
    throw ConfigTypeException(path.toString(), T, raw.runtimeType);
  } on FormatException catch (_) {
    throw ConfigTypeException(path.toString(), T, raw.runtimeType);
  }
}