describeRuntimeType function

String describeRuntimeType(
  1. Object? value, {
  2. required DiagnosticCaptureMode captureMode,
  3. required String fallback,
  4. DiagnosticResourceLimits resourceLimits = DiagnosticResourceLimits.balanced,
})

Returns the concrete class name of value, bounded by resourceLimits.

runtimeType is an overridable getter, so DiagnosticCaptureMode.balanced dispatches into caller code to read it while DiagnosticCaptureMode.strict does not. Returns fallback under strict capture, for a null value, and when the getter throws or yields an empty name.

Implementation

String describeRuntimeType(
  Object? value, {
  required DiagnosticCaptureMode captureMode,
  required String fallback,
  DiagnosticResourceLimits resourceLimits = DiagnosticResourceLimits.balanced,
}) {
  if (value == null || captureMode != DiagnosticCaptureMode.balanced) {
    return fallback;
  }
  try {
    final name = value.runtimeType.toString().trim();
    if (name.isEmpty) return fallback;
    return LogExportOutput.truncateUtf8(
      name,
      maxBytes: resourceLimits.maxCapturedValueBytes,
    );
  } on Object {
    return fallback;
  }
}