Skip to content

Commit c859d25

Browse files
committed
- Return exit code 253 in case of API errors during loading. This
will trigger for example when loading outdated snapshots. [email protected] Review URL: https://codereview.chromium.org//899523005 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43505 260f80e4-7a28-3924-810f-c04153c831b5
1 parent cae03aa commit c859d25

File tree

4 files changed

+50
-32
lines changed

4 files changed

+50
-32
lines changed

runtime/bin/main.cc

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,30 @@ static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP;
7575
// being allocated.
7676
static int vm_service_server_port = -1;
7777

78+
79+
// Exit code indicating an API error.
80+
static const int kApiErrorExitCode = 253;
81+
// Exit code indicating a compilation error.
82+
static const int kCompilationErrorExitCode = 254;
83+
// Exit code indicating an unhandled error that is not a compilation error.
84+
static const int kErrorExitCode = 255;
85+
86+
static void ErrorExit(int exit_code, const char* format, ...) {
87+
va_list arguments;
88+
va_start(arguments, format);
89+
Log::VPrintErr(format, arguments);
90+
va_end(arguments);
91+
fflush(stderr);
92+
93+
Dart_ExitScope();
94+
Dart_ShutdownIsolate();
95+
96+
Dart_Cleanup();
97+
98+
exit(exit_code);
99+
}
100+
101+
78102
// The environment provided through the command line using -D options.
79103
static dart::HashMap* environment = NULL;
80104

@@ -540,7 +564,8 @@ static Dart_Handle EnvironmentCallback(Dart_Handle name) {
540564
#define CHECK_RESULT(result) \
541565
if (Dart_IsError(result)) { \
542566
*error = strdup(Dart_GetError(result)); \
543-
*is_compile_error = Dart_IsCompilationError(result); \
567+
*exit_code = Dart_IsCompilationError(result) ? kCompilationErrorExitCode : \
568+
(Dart_IsApiError(result) ? kApiErrorExitCode : kErrorExitCode); \
544569
Dart_ExitScope(); \
545570
Dart_ShutdownIsolate(); \
546571
return NULL; \
@@ -552,7 +577,7 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
552577
const char* main,
553578
const char* package_root,
554579
char** error,
555-
bool* is_compile_error) {
580+
int* exit_code) {
556581
ASSERT(script_uri != NULL);
557582
IsolateData* isolate_data = new IsolateData(script_uri, package_root);
558583
Dart_Isolate isolate = NULL;
@@ -640,7 +665,7 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
640665
const char* package_root,
641666
void* data, char** error) {
642667
IsolateData* parent_isolate_data = reinterpret_cast<IsolateData*>(data);
643-
bool is_compile_error = false;
668+
int exit_code = 0;
644669
if (script_uri == NULL) {
645670
if (data == NULL) {
646671
*error = strdup("Invalid 'callback_data' - Unable to spawn new isolate");
@@ -663,7 +688,7 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
663688
main,
664689
package_root,
665690
error,
666-
&is_compile_error);
691+
&exit_code);
667692
}
668693

669694

@@ -765,29 +790,6 @@ char* BuildIsolateName(const char* script_name,
765790
return buffer;
766791
}
767792

768-
769-
// Exit code indicating a compilation error.
770-
static const int kCompilationErrorExitCode = 254;
771-
772-
// Exit code indicating an unhandled error that is not a compilation error.
773-
static const int kErrorExitCode = 255;
774-
775-
static void ErrorExit(int exit_code, const char* format, ...) {
776-
va_list arguments;
777-
va_start(arguments, format);
778-
Log::VPrintErr(format, arguments);
779-
va_end(arguments);
780-
fflush(stderr);
781-
782-
Dart_ExitScope();
783-
Dart_ShutdownIsolate();
784-
785-
Dart_Cleanup();
786-
787-
exit(exit_code);
788-
}
789-
790-
791793
static void DartExitOnError(Dart_Handle error) {
792794
if (!Dart_IsError(error)) {
793795
return;
@@ -982,18 +984,18 @@ void main(int argc, char** argv) {
982984
// Call CreateIsolateAndSetup which creates an isolate and loads up
983985
// the specified application script.
984986
char* error = NULL;
985-
bool is_compile_error = false;
987+
int exit_code = 0;
986988
char* isolate_name = BuildIsolateName(script_name, "main");
987989
Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name,
988990
"main",
989991
commandline_package_root,
990992
&error,
991-
&is_compile_error);
993+
&exit_code);
992994
if (isolate == NULL) {
993995
Log::PrintErr("%s\n", error);
994996
free(error);
995997
delete [] isolate_name;
996-
exit(is_compile_error ? kCompilationErrorExitCode : kErrorExitCode);
998+
exit((exit_code != 0) ? exit_code : kErrorExitCode);
997999
}
9981000
delete [] isolate_name;
9991001

runtime/tests/vm/dart/bad_snapshot

1014 Bytes
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "dart:io";
6+
import "package:expect/expect.dart";
7+
8+
main() {
9+
var result = Process.runSync(Platform.executable,
10+
[Platform.script.resolve('./bad_snapshot').toFilePath()]);
11+
print("=== stdout ===\n ${result.stdout}");
12+
print("=== stderr ===\n ${result.stderr}");
13+
Expect.equals(253, result.exitCode);
14+
}

tools/testing/dart/test_runner.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,10 @@ class CommandOutputImpl extends UniqueObject implements CommandOutput {
943943
}
944944

945945
bool get hasCrashed {
946-
// The Java dartc runner and dart2js exits with code 253 in case
947-
// of unhandled exceptions.
946+
// dart2js exits with code 253 in case of unhandled exceptions.
947+
// The dart binary exits with code 253 in case of an API error such
948+
// as an invalid snapshot file.
949+
// In either case an exit code of 253 is considered a crash.
948950
if (exitCode == 253) return true;
949951
if (io.Platform.operatingSystem == 'windows') {
950952
// The VM uses std::abort to terminate on asserts.

0 commit comments

Comments
 (0)