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

Side by Side Diff: pkg/stack_trace/lib/src/trace.dart

Issue 137443002: Validate that Trace.from's argument isn't null. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library trace; 5 library trace;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'chain.dart'; 10 import 'chain.dart';
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 var trace = new Trace.from(nativeTrace); 85 var trace = new Trace.from(nativeTrace);
86 return new LazyTrace(() => new Trace(trace.frames.skip(level + 1))); 86 return new LazyTrace(() => new Trace(trace.frames.skip(level + 1)));
87 } 87 }
88 } 88 }
89 89
90 /// Returns a new stack trace containing the same data as [trace]. 90 /// Returns a new stack trace containing the same data as [trace].
91 /// 91 ///
92 /// If [trace] is a native [StackTrace], its data will be parsed out; if it's 92 /// If [trace] is a native [StackTrace], its data will be parsed out; if it's
93 /// a [Trace], it will be returned as-is. 93 /// a [Trace], it will be returned as-is.
94 factory Trace.from(StackTrace trace) { 94 factory Trace.from(StackTrace trace) {
95 // Normally explicitly validating null arguments is bad Dart style, but here
96 // the natural failure will only occur when the LazyTrace is materialized,
97 // and we want to provide an error that's more local to the actual problem.
98 if (trace == null) {
99 throw new ArgumentError("Cannot create a Trace from null.");
100 }
101
95 if (trace is Trace) return trace; 102 if (trace is Trace) return trace;
96 if (trace is Chain) return trace.toTrace(); 103 if (trace is Chain) return trace.toTrace();
97 return new LazyTrace(() => new Trace.parse(trace.toString())); 104 return new LazyTrace(() => new Trace.parse(trace.toString()));
98 } 105 }
99 106
100 /// Parses a string representation of a stack trace. 107 /// Parses a string representation of a stack trace.
101 /// 108 ///
102 /// [trace] should be formatted in the same way as a Dart VM or browser stack 109 /// [trace] should be formatted in the same way as a Dart VM or browser stack
103 /// trace. 110 /// trace.
104 factory Trace.parse(String trace) { 111 factory Trace.parse(String trace) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // Figure out the longest path so we know how much to pad. 248 // Figure out the longest path so we know how much to pad.
242 var longest = frames.map((frame) => frame.location.length) 249 var longest = frames.map((frame) => frame.location.length)
243 .fold(0, math.max); 250 .fold(0, math.max);
244 251
245 // Print out the stack trace nicely formatted. 252 // Print out the stack trace nicely formatted.
246 return frames.map((frame) { 253 return frames.map((frame) {
247 return '${padRight(frame.location, longest)} ${frame.member}\n'; 254 return '${padRight(frame.location, longest)} ${frame.member}\n';
248 }).join(); 255 }).join();
249 } 256 }
250 } 257 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698