Skip to content

Commit b0ccaf7

Browse files
bkonyicommit-bot@chromium.org
authored andcommitted
[ VM / CLI ] Fix issue where trying to snapshot a non-existent script would cause an assertion failure
Passing --snapshot should result in the CLI being bypassed (`dart compile` should be used otherwise). Check to see if this option is provided when attempting to parse the script name and always populate script_name in that case. Fixes #43785 TEST=Added regression test to the CLI package to exercise this path. Fixed: 43785 Change-Id: Ifb67a5880f6b83c54e6deb6b0785b61fdcfc0ada Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172820 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent 2a6971c commit b0ccaf7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/dartdev/test/no_such_file_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,16 @@ void main() {
2424
expect(argsResult.stdout, isEmpty);
2525
expect(argsResult.exitCode, 64);
2626
});
27+
28+
test('Providing --snapshot VM option with invalid script fails gracefully',
29+
() {
30+
// Regression test for https://github.com/dart-lang/sdk/issues/43785
31+
p = project();
32+
final result = p.runSync('--snapshot=abc', ['foo.dart']);
33+
expect(result.stderr, isNotEmpty);
34+
expect(result.stderr,
35+
contains("Error when reading 'foo.dart': No such file or directory"));
36+
expect(result.stdout, isEmpty);
37+
expect(result.exitCode, 254);
38+
});
2739
}

runtime/bin/main_options.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ int Options::ParseArguments(int argc,
478478
bool is_potential_file_path = true;
479479
#endif // !defined(DART_PRECOMPILED_RUNTIME)
480480
if (Options::disable_dart_dev() ||
481+
(Options::snapshot_filename() != nullptr) ||
481482
(is_potential_file_path && !enable_vm_service_)) {
482483
*script_name = Utils::StrDup(argv[i]);
483484
run_script = true;

0 commit comments

Comments
 (0)