parseProviderQueueJsonText function

ParsedProviderQueue parseProviderQueueJsonText(
  1. String text, {
  2. String source = 'FA_PROVIDERS_QUEUE',
})

Parses a queue JSON text: strict decoding with line/column in every syntax error (UT-parse-strict).

Implementation

ParsedProviderQueue parseProviderQueueJsonText(
  String text, {
  String source = 'FA_PROVIDERS_QUEUE',
}) {
  final clean = text.replaceFirst('\ufeff', '').trim();
  Object? decoded;
  try {
    decoded = jsonDecode(clean);
  } on FormatException catch (error) {
    final offset = error.offset;
    final position = offset == null || offset < 0 || offset > clean.length
        ? ''
        : ' at line ${_lineOf(clean, offset)}, '
              'column ${_columnOf(clean, offset)}';
    final hint = !clean.contains('"') || clean.startsWith("'")
        ? ' — if this came from a shell single-quoted string, the single '
              'quotes are not JSON: wrap the value in single quotes and use '
              'double quotes inside'
        : '';
    throw ConfigException(
      '$source: invalid JSON$position — ${_shortJsonError(error.message)}$hint',
    );
  }
  return parseProviderQueueEntries(decoded, source: source);
}