Skip to content

Commit 85da4df

Browse files
bkonyidart-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[VM Service] Fix Windows expression evaluation type crash in experimental service
Correctly define `kRootLibraryUri` constant and forward `rootLibraryUri` to the resident frontend compiler. TAG=agy CONV=ae3a29f5-e2c8-499c-b221-ff61e40f5f1f Change-Id: Ie4c87857744d9b32165ea7d0f8004d6d6c337886 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505161 Auto-Submit: Ben Konyi <bkonyi@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
1 parent d6889ba commit 85da4df

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

pkg/dart_runtime_service_vm/lib/src/vm_expression_evaluator.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ final class VmExpressionEvaluator extends ExpressionEvaluator {
5353
static const kKlass = 'klass';
5454
static const kMethod = 'method';
5555
static const kScriptUri = 'scriptUri';
56+
static const kRootLibraryUri = 'rootLibraryUri';
5657

5758
// Keys for scope response.
5859
static const kParamNames = 'param_names';
@@ -250,6 +251,7 @@ final class VmExpressionEvaluator extends ExpressionEvaluator {
250251
offset: scope[kTokenPos] as int,
251252
scriptUri: scriptUri,
252253
isStatic: isStatic,
254+
rootLibraryUri: scope[kRootLibraryUri] as String?,
253255
serverInfoFile: backend.residentCompilerInfoFile!,
254256
);
255257
return {kKernelBytes: result.kernelBytes};

pkg/frontend_server/lib/resident_frontend_server_utils.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ Future<CompileExpressionResult> invokeCompileExpression({
247247
required int offset,
248248
required String? scriptUri,
249249
required bool isStatic,
250+
String? rootLibraryUri,
250251
required File serverInfoFile,
251252
}) async {
252253
final Map<String, Object?> response = await sendAndReceiveResponse(
@@ -264,6 +265,7 @@ Future<CompileExpressionResult> invokeCompileExpression({
264265
'offset': offset,
265266
if (scriptUri != null) 'scriptUri': scriptUri,
266267
'isStatic': isStatic,
268+
if (rootLibraryUri != null) 'rootLibraryUri': rootLibraryUri,
267269
'useCachedCompilerOptionsAsBase': true,
268270
}),
269271
serverInfoFile,

pkg/frontend_server/lib/src/resident_frontend_server.dart

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ extension on DateTime {
4848
}
4949
}
5050

51+
/// Safely converts [maybeUri] to a local file path.
52+
///
53+
/// Returns [maybeUri] as-is if it is already a raw path (e.g. `C:\foo.dart`
54+
/// or `/foo.dart`) or a non-file URI. This avoids crashes on Windows where
55+
/// drive letters (like `C:`) are incorrectly interpreted as URI schemes by
56+
/// [Uri.parse].
57+
String _maybeUriToFilename(String maybeUri) {
58+
final Uri? uri = Uri.tryParse(maybeUri);
59+
if (uri != null && (uri.scheme == 'file' || uri.scheme == '')) {
60+
try {
61+
return uri.toFilePath();
62+
} catch (_) {}
63+
}
64+
return maybeUri;
65+
}
66+
5167
enum _ResidentState { waitingForFirstCompile, compiling, waitingForRecompile }
5268

5369
/// A wrapper around the FrontendCompiler, along with all the state needed
@@ -520,16 +536,16 @@ class ResidentFrontendServer {
520536
// evaluation is taking place to compute [canonicalizedLibraryPath]
521537
// instead.
522538
canonicalizedLibraryPath = path.canonicalize(
523-
Uri.parse(request[_rootLibraryUriString]).toFilePath(),
539+
_maybeUriToFilename(request[_rootLibraryUriString]),
524540
);
525541
} else {
526542
canonicalizedLibraryPath = path.canonicalize(
527-
Uri.parse(request[_libraryUriString]).toFilePath(),
543+
_maybeUriToFilename(request[_libraryUriString]),
528544
);
529545
}
530-
} catch (e) {
546+
} catch (e, st) {
531547
return _encodeErrorMessage(
532-
"Request contains invalid '$_libraryUriString' property",
548+
"Request contains invalid '$_libraryUriString' property: $e\n$st",
533549
);
534550
}
535551

0 commit comments

Comments
 (0)