boundedPrettyFormatBody function

String boundedPrettyFormatBody(
  1. Object? data, {
  2. int budget = 2000,
  3. int maxListItems = 50,
  4. int maxStringLength = 2000,
})

Like prettyFormatBody, but bounds total work via _boundForLogging for an eager caller with no later display step to defer cost to.

Implementation

String boundedPrettyFormatBody(
  Object? data, {
  int budget = 2000,
  int maxListItems = 50,
  int maxStringLength = 2000,
}) {
  if (data == null) return 'null';
  if (data is Uint8List) return _formatBytes(data);
  if (data is FormData) return _formatFormData(data);
  Object? value;
  try {
    value = data is String ? jsonDecode(data) : data;
  } catch (_) {
    return data.toString();
  }
  final remaining = [budget];
  final bounded = _boundForLogging(
    value,
    remaining,
    maxListItems: maxListItems,
    maxStringLength: maxStringLength,
  );
  try {
    return const JsonEncoder.withIndent('  ').convert(bounded);
  } catch (_) {
    return bounded.toString();
  }
}