From 8e4c2d6ceeb505048808cec8e1f89d2dd91b2f3d Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Wed, 26 Jun 2024 19:58:11 +0000 Subject: [PATCH] [vm] Fix link to learn more about missing main function The previous link no longer lead to a relevant destination. While I can add a client-side redirect on dart.dev, this CL updates the link to a redirect we can better guarantee as up to date in the long term. TEST=vm/cc/DartAPI_RootLibraryMissingMain Change-Id: I1e9dbf7a32c1468c308e9cf00d96575ba3c24695 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373322 Reviewed-by: Slava Egorov Reviewed-by: Ryan Macnak Commit-Queue: Ryan Macnak --- runtime/vm/dart_api_impl.cc | 3 +-- runtime/vm/dart_api_impl_test.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index d43edd7a412..97ba0768f98 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -5440,8 +5440,7 @@ DART_EXPORT Dart_Handle Dart_LoadScriptFromKernel(const uint8_t* buffer, if (tmp.IsNull()) { return Api::NewError( "Invoked Dart programs must have a 'main' function defined:\n" - "https://dart.dev/guides/language/" - "language-tour#a-basic-dart-program"); + "https://dart.dev/to/main-function"); } library ^= tmp.ptr(); IG->object_store()->set_root_library(library); diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index f1c4e949b0d..b164ae00c97 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -7488,6 +7488,19 @@ TEST_CASE(DartAPI_RootLibrary) { EXPECT(Dart_IsNull(root_lib)); // Root library did change. } +TEST_CASE(DartAPI_RootLibraryMissingMain) { + const char* kScriptChars = + "notMain() {" + " return 12345;" + "}"; + + Dart_Handle result = LoadScript(TestCase::url(), kScriptChars); + + EXPECT_ERROR(result, + "Invoked Dart programs must have a 'main' function defined:\n" + "https://dart.dev/to/main-function"); +} + TEST_CASE(DartAPI_LookupLibrary) { const char* kScriptChars = "import 'library1_dart';"