@@ -11,6 +11,7 @@ import '../debugging/dart_scope.dart';
1111import '../debugging/inspector.dart' ;
1212import '../debugging/location.dart' ;
1313import '../debugging/modules.dart' ;
14+ import '../loaders/strategy.dart' ;
1415import '../utilities/objects.dart' as chrome;
1516import 'expression_compiler.dart' ;
1617
@@ -23,6 +24,7 @@ class ErrorKind {
2324 static const ErrorKind reference = ErrorKind ._('ReferenceError' );
2425 static const ErrorKind internal = ErrorKind ._('InternalError' );
2526 static const ErrorKind invalidInput = ErrorKind ._('InvalidInputError' );
27+ static const ErrorKind loadModule = ErrorKind ._('LoadModuleError' );
2628
2729 @override
2830 String toString () => _kind;
@@ -33,17 +35,26 @@ class ErrorKind {
3335/// collect context for evaluation (scope, types, modules), and using
3436/// ExpressionCompilerInterface to compile dart expressions to JavaScript.
3537class ExpressionEvaluator {
38+ final String _entrypoint;
3639 final AppInspector _inspector;
3740 final Locations _locations;
3841 final Modules _modules;
3942 final ExpressionCompiler _compiler;
4043 final _logger = Logger ('ExpressionEvaluator' );
4144
45+ /// Strip synthetic library name from compiler error messages.
4246 static final _syntheticNameFilterRegex =
4347 RegExp ('org-dartlang-debug:synthetic_debug_expression:.*:.*Error: ' );
4448
45- ExpressionEvaluator (
46- this ._inspector, this ._locations, this ._modules, this ._compiler);
49+ /// Find module path from the XHR call network error message received from chrome.
50+ ///
51+ /// Example:
52+ /// NetworkError: Failed to load 'http://<hostname>.com/path/to/module.js?<cache_busting_token>'
53+ static final _loadModuleErrorRegex =
54+ RegExp (r".*Failed to load '.*\.com/(.*\.js).*" );
55+
56+ ExpressionEvaluator (this ._entrypoint, this ._inspector, this ._locations,
57+ this ._modules, this ._compiler);
4758
4859 RemoteObject _createError (ErrorKind severity, String message) {
4960 return RemoteObject (
@@ -107,10 +118,10 @@ class ExpressionEvaluator {
107118 ' return $inner (t);'
108119 '}' ;
109120 result = await _inspector.callFunction (function, scope.values);
110- result = _formatEvaluationError (result);
121+ result = await _formatEvaluationError (result);
111122 } else {
112123 result = await _inspector.debugger.evaluate (jsResult);
113- result = _formatEvaluationError (result);
124+ result = await _formatEvaluationError (result);
114125 }
115126
116127 _logger.finest ('Evaluated "$expression " to "$result "' );
@@ -199,7 +210,7 @@ class ExpressionEvaluator {
199210 // Send JS expression to chrome to evaluate.
200211 var result = await _inspector.debugger
201212 .evaluateJsOnCallFrameIndex (frameIndex, jsResult);
202- result = _formatEvaluationError (result);
213+ result = await _formatEvaluationError (result);
203214
204215 _logger.finest ('Evaluated "$expression " to "$result "' );
205216 return result;
@@ -240,16 +251,26 @@ class ExpressionEvaluator {
240251 return _createError (ErrorKind .compilation, error);
241252 }
242253
243- RemoteObject _formatEvaluationError (RemoteObject result) {
254+ Future < RemoteObject > _formatEvaluationError (RemoteObject result) async {
244255 if (result.type == 'string' ) {
245256 var error = '${result .value }' ;
246257 if (error.startsWith ('ReferenceError: ' )) {
247258 error = error.replaceFirst ('ReferenceError: ' , '' );
248259 return _createError (ErrorKind .reference, error);
249- }
250- if (error.startsWith ('TypeError: ' )) {
260+ } else if (error.startsWith ('TypeError: ' )) {
251261 error = error.replaceFirst ('TypeError: ' , '' );
252262 return _createError (ErrorKind .type, error);
263+ } else if (error.startsWith ('NetworkError: ' )) {
264+ var modulePath = _loadModuleErrorRegex.firstMatch (error)? .group (1 );
265+ var module = modulePath != null
266+ ? await globalLoadStrategy.moduleForServerPath (
267+ _entrypoint, modulePath)
268+ : 'unknown' ;
269+ modulePath ?? = 'unknown' ;
270+ error = 'Module is not loaded : $module (path: $modulePath ). '
271+ 'Accessing libraries that have not yet been used in the '
272+ 'application is not supported during expression evaluation.' ;
273+ return _createError (ErrorKind .loadModule, error);
253274 }
254275 }
255276 return result;
0 commit comments