Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: lib/src/chain.dart

Issue 963893002: Make padding consistent across all stack traces for Chain.toString(). (Closed) Base URL: git@github.com:dart-lang/stack_trace@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « README.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/chain.dart
diff --git a/lib/src/chain.dart b/lib/src/chain.dart
index 9555e76fa0938202f53cb34300adef6cd395a88f..03dbed63fb74663738a1e550d4b1c5d158513a5f 100644
--- a/lib/src/chain.dart
+++ b/lib/src/chain.dart
@@ -6,6 +6,7 @@ library stack_trace.chain;
import 'dart:async';
import 'dart:collection';
+import 'dart:math' as math;
import 'frame.dart';
import 'stack_zone_specification.dart';
@@ -15,6 +16,10 @@ import 'utils.dart';
/// A function that handles errors in the zone wrapped by [Chain.capture].
typedef void ChainHandler(error, Chain chain);
+/// The line used in the string representation of stack chains to represent
+/// the gap between traces.
+const _gap = '===== asynchronous gap ===========================\n';
+
/// A chain of stack traces.
///
/// A stack chain is a collection of one or more stack traces that collectively
@@ -36,9 +41,6 @@ typedef void ChainHandler(error, Chain chain);
/// "$stackChain");
/// });
class Chain implements StackTrace {
- /// The line used in the string representation of stack chains to represent
- /// the gap between traces.
- static const _GAP = '===== asynchronous gap ===========================\n';
/// The stack traces that make up this chain.
///
@@ -180,5 +182,19 @@ class Chain implements StackTrace {
/// in the chain.
Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames)));
- String toString() => traces.join(_GAP);
+ String toString() {
+ // Figure out the longest path so we know how much to pad.
+ var longest = traces.map((trace) {
+ return trace.frames.map((frame) => frame.location.length)
+ .fold(0, math.max);
+ }).fold(0, math.max);
+
+ // Don't call out to [Trace.toString] here because that doesn't ensure that
+ // padding is consistent across all traces.
+ return traces.map((trace) {
+ return trace.frames.map((frame) {
+ return '${padRight(frame.location, longest)} ${frame.member}\n';
+ }).join();
+ }).join(_gap);
+ }
}
« no previous file with comments | « README.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698