Skip to content

Commit

Permalink
[ VM / CLI ] Fix issue where trying to snapshot a non-existent script…
Browse files Browse the repository at this point in the history
… 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 <aam@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
  • Loading branch information
bkonyi authored and commit-bot@chromium.org committed Nov 18, 2020
1 parent 2a6971c commit b0ccaf7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/dartdev/test/no_such_file_test.dart
Expand Up @@ -24,4 +24,16 @@ void main() {
expect(argsResult.stdout, isEmpty);
expect(argsResult.exitCode, 64);
});

test('Providing --snapshot VM option with invalid script fails gracefully',
() {
// Regression test for https://github.com/dart-lang/sdk/issues/43785
p = project();
final result = p.runSync('--snapshot=abc', ['foo.dart']);
expect(result.stderr, isNotEmpty);
expect(result.stderr,
contains("Error when reading 'foo.dart': No such file or directory"));
expect(result.stdout, isEmpty);
expect(result.exitCode, 254);
});
}
1 change: 1 addition & 0 deletions runtime/bin/main_options.cc
Expand Up @@ -478,6 +478,7 @@ int Options::ParseArguments(int argc,
bool is_potential_file_path = true;
#endif // !defined(DART_PRECOMPILED_RUNTIME)
if (Options::disable_dart_dev() ||
(Options::snapshot_filename() != nullptr) ||
(is_potential_file_path && !enable_vm_service_)) {
*script_name = Utils::StrDup(argv[i]);
run_script = true;
Expand Down

0 comments on commit b0ccaf7

Please sign in to comment.