void CJavascriptException::ThrowIf(v8::Isolate *isolate, v8::TryCatch& try_catch) { if (try_catch.HasCaught() && try_catch.CanContinue()) { v8::HandleScope handle_scope(isolate); PyObject *type = NULL; v8::Handle<v8::Value> obj = try_catch.Exception(); if (obj->IsObject()) { v8::Handle<v8::Object> exc = obj->ToObject(); v8::Handle<v8::String> name = v8::String::NewFromUtf8(isolate, "name"); if (exc->Has(name)) { v8::String::Utf8Value s(v8::Handle<v8::String>::Cast(exc->Get(name))); for (size_t i=0; i<_countof(SupportErrors); i++) { if (strnicmp(SupportErrors[i].name, *s, s.length()) == 0) { type = SupportErrors[i].type; } } } } throw CJavascriptException(isolate, try_catch, type); } }
void Executor::HandleV8Error (v8::TryCatch& tryCatch, v8::Handle<v8::Value>& result) { ISOLATE; if (tryCatch.HasCaught()) { // caught a V8 exception if (! tryCatch.CanContinue()) { // request was cancelled TRI_GET_GLOBALS(); v8g->_canceled = true; THROW_ARANGO_EXCEPTION(TRI_ERROR_REQUEST_CANCELED); } // request was not cancelled, but some other error occurred // peek into the exception if (tryCatch.Exception()->IsObject()) { // cast the exception to an object v8::Handle<v8::Array> objValue = v8::Handle<v8::Array>::Cast(tryCatch.Exception()); v8::Handle<v8::String> errorNum = TRI_V8_ASCII_STRING("errorNum"); v8::Handle<v8::String> errorMessage = TRI_V8_ASCII_STRING("errorMessage"); if (objValue->HasOwnProperty(errorNum) && objValue->HasOwnProperty(errorMessage)) { v8::Handle<v8::Value> errorNumValue = objValue->Get(errorNum); v8::Handle<v8::Value> errorMessageValue = objValue->Get(errorMessage); // found something that looks like an ArangoError if ((errorNumValue->IsNumber() || errorNumValue->IsNumberObject()) && (errorMessageValue->IsString() || errorMessageValue->IsStringObject())) { int errorCode = static_cast<int>(TRI_ObjectToInt64(errorNumValue)); std::string const errorMessage(TRI_ObjectToString(errorMessageValue)); THROW_ARANGO_EXCEPTION_MESSAGE(errorCode, errorMessage); } } // exception is no ArangoError std::string const details(TRI_ObjectToString(tryCatch.Exception())); THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_QUERY_SCRIPT, details); } // we can't figure out what kind of error occured and throw a generic error THROW_ARANGO_EXCEPTION(TRI_ERROR_INTERNAL); } if (result.IsEmpty()) { THROW_ARANGO_EXCEPTION(TRI_ERROR_INTERNAL); } // if we get here, no exception has been raised }
/// @brief checks if a V8 exception has occurred and throws an appropriate C++ /// exception from it if so void Executor::HandleV8Error(v8::TryCatch& tryCatch, v8::Handle<v8::Value>& result, arangodb::basics::StringBuffer* const buffer, bool duringCompile) { ISOLATE; if (tryCatch.HasCaught()) { // caught a V8 exception if (!tryCatch.CanContinue()) { // request was canceled TRI_GET_GLOBALS(); v8g->_canceled = true; THROW_ARANGO_EXCEPTION(TRI_ERROR_REQUEST_CANCELED); } // request was not canceled, but some other error occurred // peek into the exception if (tryCatch.Exception()->IsObject()) { // cast the exception to an object v8::Handle<v8::Array> objValue = v8::Handle<v8::Array>::Cast(tryCatch.Exception()); v8::Handle<v8::String> errorNum = TRI_V8_ASCII_STRING("errorNum"); v8::Handle<v8::String> errorMessage = TRI_V8_ASCII_STRING("errorMessage"); TRI_Utf8ValueNFC stacktrace(TRI_UNKNOWN_MEM_ZONE, tryCatch.StackTrace()); if (objValue->HasOwnProperty(errorNum) && objValue->HasOwnProperty(errorMessage)) { v8::Handle<v8::Value> errorNumValue = objValue->Get(errorNum); v8::Handle<v8::Value> errorMessageValue = objValue->Get(errorMessage); // found something that looks like an ArangoError if ((errorNumValue->IsNumber() || errorNumValue->IsNumberObject()) && (errorMessageValue->IsString() || errorMessageValue->IsStringObject())) { int errorCode = static_cast<int>(TRI_ObjectToInt64(errorNumValue)); std::string errorMessage(TRI_ObjectToString(errorMessageValue)); if (*stacktrace && stacktrace.length() > 0) { errorMessage += "\nstacktrace of offending AQL function: "; errorMessage += *stacktrace; } THROW_ARANGO_EXCEPTION_MESSAGE(errorCode, errorMessage); } } // exception is no ArangoError std::string details(TRI_ObjectToString(tryCatch.Exception())); if (buffer) { std::string script(buffer->c_str(), buffer->length()); LOG(ERR) << details << " " << script; details += "\nSee log for more details"; } if (*stacktrace && stacktrace.length() > 0) { details += "\nstacktrace of offending AQL function: "; details += *stacktrace; } THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_QUERY_SCRIPT, details); } std::string msg("unknown error in scripting"); if (duringCompile) { msg += " (during compilation)"; } if (buffer) { std::string script(buffer->c_str(), buffer->length()); LOG(ERR) << msg << " " << script; msg += " See log for details"; } // we can't figure out what kind of error occurred and throw a generic error THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, msg); } if (result.IsEmpty()) { std::string msg("unknown error in scripting"); if (duringCompile) { msg += " (during compilation)"; } if (buffer) { std::string script(buffer->c_str(), buffer->length()); LOG(ERR) << msg << " " << script; msg += " See log for details"; } THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, msg); } // if we get here, no exception has been raised }