Flutter Engine
dart_error.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include "tonic/common/macros.h"
9 
10 namespace tonic {
11 namespace DartError {
12 const char kInvalidArgument[] = "Invalid argument.";
13 } // namespace DartError
14 
15 bool LogIfError(Dart_Handle handle) {
16  if (Dart_IsUnhandledExceptionError(handle)) {
17  Dart_Handle exception_handle = Dart_ErrorGetException(handle);
18  const std::string exception =
19  tonic::StdStringFromDart(Dart_ToString(exception_handle));
20  Dart_Handle stack_trace_handle = Dart_ErrorGetStackTrace(handle);
21  const std::string stack_trace =
22  tonic::StdStringFromDart(Dart_ToString(stack_trace_handle));
23  tonic::Log("Dart Unhandled Exception: %s, stack trace: %s",
24  exception.c_str(), stack_trace.c_str());
25  return true;
26  } else if (Dart_IsError(handle)) {
27  tonic::Log("Dart Error: %s", Dart_GetError(handle));
28  return true;
29  } else {
30  return false;
31  }
32 }
33 
35  if (Dart_IsCompilationError(handle)) {
36  return kCompilationErrorType;
37  } else if (Dart_IsApiError(handle)) {
38  return kApiErrorType;
39  } else if (Dart_IsError(handle)) {
40  return kUnknownErrorType;
41  } else {
42  return kNoError;
43  }
44 }
45 
46 int GetErrorExitCode(Dart_Handle handle) {
47  if (Dart_IsCompilationError(handle)) {
48  return 254; // dart::bin::kCompilationErrorExitCode
49  } else if (Dart_IsApiError(handle)) {
50  return 253; // dart::bin::kApiErrorExitCode
51  } else if (Dart_IsError(handle)) {
52  return 255; // dart::bin::kErrorExitCode
53  } else {
54  return 0;
55  }
56 }
57 
58 } // namespace tonic
const char kInvalidArgument[]
Definition: dart_error.cc:12
void Log(const char *format,...)
Definition: log.cc:19
int GetErrorExitCode(Dart_Handle handle)
Definition: dart_error.cc:46
DartErrorHandleType GetErrorHandleType(Dart_Handle handle)
Definition: dart_error.cc:34
DartErrorHandleType
Definition: dart_error.h:18
std::string StdStringFromDart(Dart_Handle handle)
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15