parseProviderTimeouts function

ProviderTimeoutsOverride? parseProviderTimeouts(
  1. Object? node
)

Parses the providerTimeouts: section: provider watchdog overrides (see ProviderTimeoutsOverride). Strict — a bad schema throws ConfigException instead of silently keeping the defaults. Public so the settings-hub resilience flow (issue #393) reloads the saved section with the SAME parser boot uses.

Implementation

ProviderTimeoutsOverride? parseProviderTimeouts(Object? node) {
  if (node == null) return null;
  if (node is! YamlMap) {
    throw ConfigException('providerTimeouts must be a map, got: $node');
  }
  Duration? readTimeout(String key) {
    final value = node[key];
    if (value == null) return null;
    if (value is! int || value <= 0) {
      throw ConfigException(
        '"providerTimeouts.$key" must be a positive integer (milliseconds)',
      );
    }
    return Duration(milliseconds: value);
  }

  final connect = readTimeout('connectTimeoutMs');
  final streamIdle = readTimeout('streamIdleTimeoutMs');
  for (final key in node.keys) {
    if (key != 'connectTimeoutMs' && key != 'streamIdleTimeoutMs') {
      throw ConfigException('unknown "providerTimeouts" key: $key');
    }
  }
  if (connect == null && streamIdle == null) return null;
  return ProviderTimeoutsOverride(connect: connect, streamIdle: streamIdle);
}