Skip to content

Commit 9b77ab3

Browse files
author
Anna Gringauze
authored
Better error handling for LoadStrategy (#1744)
* Better error handling for LoadStrategy * update version, changelog, and build
1 parent f480bfc commit 9b77ab3

File tree

8 files changed

+163
-135
lines changed

8 files changed

+163
-135
lines changed

dwds/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 16.0.1-dev
2+
3+
- Allow `LoadStrategy.serverPathForModule` and `LoadStrategy.sourceMapPathForModule`
4+
to return `null` and add error handling.
5+
16
## 16.0.0
27

38
- Fix a hang and report errors on hot reload exceptions from the injected

dwds/lib/src/debugging/location.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,16 @@ class Locations {
286286
}
287287
final modulePath =
288288
await globalLoadStrategy.serverPathForModule(_entrypoint, module);
289+
if (modulePath == null) {
290+
_logger.warning('No module path for module: $module');
291+
return result;
292+
}
289293
final sourceMapPath =
290294
await globalLoadStrategy.sourceMapPathForModule(_entrypoint, module);
295+
if (sourceMapPath == null) {
296+
_logger.warning('No sourceMap path for module: $module');
297+
return result;
298+
}
291299
final sourceMapContents =
292300
await _assetReader.sourceMapContents(sourceMapPath);
293301
final scriptLocation =

dwds/lib/src/injected/client.js

Lines changed: 118 additions & 106 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/lib/src/loaders/build_runner_require.dart

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,16 @@ class BuildRunnerRequireStrategyProvider {
8484
return null;
8585
}
8686

87-
Future<String> _serverPathForModule(
87+
Future<String?> _serverPathForModule(
8888
MetadataProvider metadataProvider, String module) async {
89-
final result = stripTopLevelDirectory(
90-
(await metadataProvider.moduleToModulePath)[module] ?? '');
91-
return result;
89+
final modulePath = (await metadataProvider.moduleToModulePath)[module];
90+
return modulePath == null ? null : stripTopLevelDirectory(modulePath);
9291
}
9392

94-
Future<String> _sourceMapPathForModule(
93+
Future<String?> _sourceMapPathForModule(
9594
MetadataProvider metadataProvider, String module) async {
96-
final path = (await metadataProvider.moduleToSourceMap)[module] ?? '';
97-
return stripTopLevelDirectory(path);
95+
final sourceMapPath = (await metadataProvider.moduleToSourceMap)[module];
96+
return sourceMapPath == null ? null : stripTopLevelDirectory(sourceMapPath);
9897
}
9998

10099
String? _serverPathForAppUri(String appUrl) {
@@ -115,13 +114,17 @@ class BuildRunnerRequireStrategyProvider {
115114
final result = <String, ModuleInfo>{};
116115
for (var module in modules) {
117116
final serverPath = await _serverPathForModule(metadataProvider, module);
118-
result[module] = ModuleInfo(
119-
// TODO: Save locations of full kernel files in ddc metadata.
120-
// Issue: https://github.com/dart-lang/sdk/issues/43684
121-
// TODO: Change these to URIs instead of paths when the SDK supports
122-
// it.
123-
p.setExtension(serverPath, '.full.dill'),
124-
p.setExtension(serverPath, '.dill'));
117+
if (serverPath == null) {
118+
_logger.warning('No module info found for module $module');
119+
} else {
120+
result[module] = ModuleInfo(
121+
// TODO: Save locations of full kernel files in ddc metadata.
122+
// Issue: https://github.com/dart-lang/sdk/issues/43684
123+
// TODO: Change these to URIs instead of paths when the SDK supports
124+
// it.
125+
p.setExtension(serverPath, '.full.dill'),
126+
p.setExtension(serverPath, '.dill'));
127+
}
125128
}
126129
return result;
127130
}

dwds/lib/src/loaders/legacy.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LegacyStrategy extends LoadStrategy {
2020
///
2121
/// /packages/path/path.ddc.js -> packages/path/path
2222
///
23-
final Future<String> Function(
23+
final Future<String?> Function(
2424
MetadataProvider metadataProvider, String sourcePath)
2525
_moduleForServerPath;
2626

@@ -39,7 +39,7 @@ class LegacyStrategy extends LoadStrategy {
3939
///
4040
/// web/main -> main.ddc.js
4141
///
42-
final Future<String> Function(
42+
final Future<String?> Function(
4343
MetadataProvider metadataProvider, String module) _serverPathForModule;
4444

4545
/// Returns the source map path for the provided module.
@@ -48,7 +48,7 @@ class LegacyStrategy extends LoadStrategy {
4848
///
4949
/// web/main -> main.ddc.js.map
5050
///
51-
final Future<String> Function(
51+
final Future<String?> Function(
5252
MetadataProvider metadataProvider, String module) _sourceMapPathForModule;
5353

5454
/// Returns the server path for the app uri.
@@ -101,7 +101,7 @@ class LegacyStrategy extends LoadStrategy {
101101
'window.\$dartLoader.forceLoadModule("$clientScript");\n';
102102

103103
@override
104-
Future<String> moduleForServerPath(
104+
Future<String?> moduleForServerPath(
105105
String entrypoint, String serverPath) async =>
106106
_moduleForServerPath(metadataProviderFor(entrypoint), serverPath);
107107

@@ -110,11 +110,11 @@ class LegacyStrategy extends LoadStrategy {
110110
_moduleInfoForProvider(metadataProviderFor(entrypoint));
111111

112112
@override
113-
Future<String> serverPathForModule(String entrypoint, String module) async =>
113+
Future<String?> serverPathForModule(String entrypoint, String module) async =>
114114
_serverPathForModule(metadataProviderFor(entrypoint), module);
115115

116116
@override
117-
Future<String> sourceMapPathForModule(
117+
Future<String?> sourceMapPathForModule(
118118
String entrypoint, String module) async =>
119119
_sourceMapPathForModule(metadataProviderFor(entrypoint), module);
120120

dwds/lib/src/loaders/require.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class RequireStrategy extends LoadStrategy {
102102
///
103103
/// web/main -> main.ddc.js
104104
///
105-
final Future<String> Function(MetadataProvider provider, String module)
105+
final Future<String?> Function(MetadataProvider provider, String module)
106106
_serverPathForModule;
107107

108108
/// Returns the source map path for the provided module.
@@ -111,7 +111,7 @@ class RequireStrategy extends LoadStrategy {
111111
///
112112
/// web/main -> main.ddc.js.map
113113
///
114-
final Future<String> Function(MetadataProvider provider, String module)
114+
final Future<String?> Function(MetadataProvider provider, String module)
115115
_sourceMapPathForModule;
116116

117117
/// Returns the server path for the app uri.
@@ -276,13 +276,13 @@ if(!window.\$requireLoader) {
276276
}
277277

278278
@override
279-
Future<String> serverPathForModule(String entrypoint, String module) {
279+
Future<String?> serverPathForModule(String entrypoint, String module) {
280280
final metadataProvider = metadataProviderFor(entrypoint);
281281
return _serverPathForModule(metadataProvider, module);
282282
}
283283

284284
@override
285-
Future<String> sourceMapPathForModule(String entrypoint, String module) {
285+
Future<String?> sourceMapPathForModule(String entrypoint, String module) {
286286
final metadataProvider = metadataProviderFor(entrypoint);
287287
return _sourceMapPathForModule(metadataProvider, module);
288288
}

dwds/lib/src/loaders/strategy.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ abstract class LoadStrategy {
9393
///
9494
/// web/main -> main.ddc.js
9595
///
96-
Future<String> serverPathForModule(String entrypoint, String module);
96+
Future<String?> serverPathForModule(String entrypoint, String module);
9797

9898
/// Returns the source map path for the provided module.
9999
///
100100
/// For example:
101101
///
102102
/// web/main -> main.ddc.js.map
103103
///
104-
Future<String> sourceMapPathForModule(String entrypoint, String module);
104+
Future<String?> sourceMapPathForModule(String entrypoint, String module);
105105

106106
/// Returns a map from module id to module info for the provided entrypoint.
107107
///

webdev/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ dev_dependencies:
4949
webdriver: ^3.0.0
5050

5151
# Comment out before releasing webdev.
52-
# dependency_overrides:
53-
# dwds:
54-
# path: ../dwds
52+
dependency_overrides:
53+
dwds:
54+
path: ../dwds
5555

5656
executables:
5757
webdev:

0 commit comments

Comments
 (0)