formatInstanceRef function

String formatInstanceRef(
  1. Object? value
)

Best-effort pretty-print for a raw VM Service evaluate result.

Unwraps InstanceRef into the value the user typed at the prompt instead of dumping the raw VM internal shape:

  • Primitive scalars carry their printed form on valueAsString. The string is returned verbatim, with "..." quoting added when the underlying kind is String.
  • Non-primitive InstanceRefs render as <ClassName#id>.
  • ErrorRef renders as Error: <message>.
  • Plain Dart objects fall through to their toString.

Implementation

String formatInstanceRef(Object? value) {
  if (value == null) return 'null';
  if (value is InstanceRef) {
    final printed = value.valueAsString;
    if (printed != null) {
      return value.kind == 'String' ? '"$printed"' : printed;
    }
    final className = value.classRef?.name ?? 'Instance';
    return '<$className#${value.id ?? '?'}>';
  }
  if (value is ErrorRef) return 'Error: ${value.message ?? value.id}';
  return value.toString();
}