getFullString method

Future<String?> getFullString(
  1. ThreadInfo thread,
  2. InstanceRef? ref
)

Helper to convert to InstanceRef to a complete untruncated unquoted String, handling vm.InstanceKind.kNull which is the type for the unused fields of a log event.

If the request to the VM results in an error (for example because the string was collected), returns the original truncated string followed by … (if available).

Implementation

Future<String?> getFullString(ThreadInfo thread, vm.InstanceRef? ref) async {
  if (ref == null || ref.kind == vm.InstanceKind.kNull) {
    return null;
  }
  return _converter
      .convertVmInstanceRefToDisplayString(
    thread,
    ref,
    // Always allow calling toString() here as the caller expects the full
    // string regardless of the evaluateToStringInDebugViews setting.
    allowCallingToString: true,
    allowTruncatedValue: false,
    format: VariableFormat.noQuotes(),
  )
      // Fetching strings from the server may throw if they have been
      // collected since (for example if a Hot Restart occurs while
      // we're running this) or if the app is terminating. Log the error and
      // fall back to the truncated string if one is available.
      .then<String?>(
    (s) => s,
    onError: (Object e) {
      logger?.call('$e');
      if (ref.valueAsString case var valueAsString?) {
        return '$valueAsString…';
      }
      return null;
    },
  );
}