Improved error handling and logging (#1187)
diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md
index f558677..67e9ab9 100644
--- a/dwds/CHANGELOG.md
+++ b/dwds/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 7.1.1 - Unreleased
+
+- Properly handle `requireJS` errors during hot restarts.
+
## 7.1.0
- Fix a potential null issue while resuming.
diff --git a/dwds/lib/src/dwds_vm_client.dart b/dwds/lib/src/dwds_vm_client.dart
index 22580f9..37264cb 100644
--- a/dwds/lib/src/dwds_vm_client.dart
+++ b/dwds/lib/src/dwds_vm_client.dart
@@ -61,7 +61,9 @@
await _disableBreakpointsAndResume(client, chromeProxyService);
int context;
try {
+ _logger.info('Attempting to get execution context ID.');
context = await chromeProxyService.executionContext.id;
+ _logger.info('Got execution context ID.');
} on StateError catch (e) {
// We couldn't find the execution context. `hotRestart` may have been
// triggered in the middle of a full reload.
@@ -76,12 +78,14 @@
// restart. Only return success after the isolate has fully started.
var stream = chromeProxyService.onEvent('Isolate');
try {
+ _logger.info('Issuing \$dartHotRestart request.');
await chromeProxyService.remoteDebugger
.sendCommand('Runtime.evaluate', params: {
'expression': r'$dartHotRestart();',
'awaitPromise': true,
'contextId': context,
});
+ _logger.info('\$dartHotRestart request complete.');
} on WipError catch (exception) {
var code = exception.error['code'];
// This corresponds to `Execution context was destroyed` which can
@@ -96,6 +100,8 @@
};
}
}
+
+ _logger.info('Waiting for Isolate Start event.');
await stream.firstWhere((event) => event.kind == EventKind.kIsolateStart);
_logger.info('Successful hot restart');
return {'result': Success().toJson()};
diff --git a/dwds/lib/src/loaders/require.dart b/dwds/lib/src/loaders/require.dart
index 0081397..58078c2 100644
--- a/dwds/lib/src/loaders/require.dart
+++ b/dwds/lib/src/loaders/require.dart
@@ -216,28 +216,25 @@
digestsPath: '$_requireDigestsPath?entrypoint=$entrypoint',
// Used in package:build_runner/src/server/build_updates_client/hot_reload_client.dart
moduleParentsGraph: new Map(),
- moduleLoadingErrorCallbacks: new Map(),
forceLoadModule: function (modulePath, callback, onError) {
let moduleName = moduleNames[modulePath];
if (moduleName == null) {
moduleName = modulePath;
}
- if (typeof onError != 'undefined') {
- var errorCallbacks = \$requireLoader.moduleLoadingErrorCallbacks;
- if (!errorCallbacks.has(moduleName)) {
- errorCallbacks.set(moduleName, new Set());
- }
- errorCallbacks.get(moduleName).add(onError);
- }
requirejs.undef(moduleName);
- requirejs([moduleName], function() {
- if (typeof onError != 'undefined') {
- errorCallbacks.get(moduleName).delete(onError);
- }
- if (typeof callback != 'undefined') {
- callback();
- }
- });
+ try{
+ requirejs([moduleName], function() {
+ if (typeof callback != 'undefined') {
+ callback();
+ }
+ });
+ } catch (error) {
+ if (typeof onError != 'undefined') {
+ onError(error);
+ }else{
+ throw(error);
+ }
+ }
},
getModuleLibraries: null, // set up by _initializeTools
};
diff --git a/dwds/lib/src/version.dart b/dwds/lib/src/version.dart
index a8a1383..5d7be62 100644
--- a/dwds/lib/src/version.dart
+++ b/dwds/lib/src/version.dart
@@ -1,2 +1,2 @@
// Generated code. Do not modify.
-const packageVersion = '7.1.0';
+const packageVersion = '7.1.1';
diff --git a/dwds/pubspec.yaml b/dwds/pubspec.yaml
index ad70944..aebbdc6 100644
--- a/dwds/pubspec.yaml
+++ b/dwds/pubspec.yaml
@@ -1,6 +1,6 @@
name: dwds
# Every time this changes you need to run `pub run build_runner build`.
-version: 7.1.0
+version: 7.1.1
homepage: https://github.com/dart-lang/webdev/tree/master/dwds
description: >-
A service that proxies between the Chrome debug protocol and the Dart VM