diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp index f94a568d46ee512ca5c2d7f35613a508411456ab..e4cc6575f96064f6558a1b04db9fc16ecffc5cb0 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp @@ -882,7 +882,7 @@ static napi_value GetTopWindowTask(void* contextPtr, napi_env env, napi_value ca if (lists->ability->GetWindow() == nullptr) { lists->errorCode = newApi ? static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY) : static_cast(WMError::WM_ERROR_NULLPTR); - lists->errMsg = "FA mode can not get ability window"; + lists->errMsg = "[window][getLastWindow]msg: FA mode can not get ability window"; return; } lists->window = Window::GetTopWindowWithId(lists->ability->GetWindow()->GetWindowId()); @@ -891,7 +891,7 @@ static napi_value GetTopWindowTask(void* contextPtr, napi_env env, napi_value ca if (contextPtr == nullptr || context == nullptr) { lists->errorCode = newApi ? static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY) : static_cast(WMError::WM_ERROR_NULLPTR); - lists->errMsg = "Stage mode without context"; + lists->errMsg = "[window][getLastWindow]msg: Stage mode without context"; return; } lists->window = Window::GetTopWindowWithContext(context->lock()); @@ -901,9 +901,10 @@ static napi_value GetTopWindowTask(void* contextPtr, napi_env env, napi_value ca if (lists == nullptr) { if (newApi) { task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "napi abnormal")); + "[window][getLastWindow]msg: NAPI abnormal")); } else { - task.Reject(env, JsErrUtils::CreateJsError(env, WMError::WM_ERROR_NULLPTR, "napi abnormal")); + task.Reject(env, JsErrUtils::CreateJsError(env, WMError::WM_ERROR_NULLPTR, + "[window][getLastWindow]msg: NAPI abnormal")); } return; } @@ -921,10 +922,10 @@ static napi_value GetTopWindowTask(void* contextPtr, napi_env env, napi_value ca if (lists->window == nullptr || lists->window->GetWindowState() == WindowState::STATE_DESTROYED) { if (newApi) { task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "Get top window failed")); + "[window][getLastWindow]msg: Get top window failed")); } else { task.Reject(env, JsErrUtils::CreateJsError(env, WMError::WM_ERROR_NULLPTR, - "Get top window failed")); + "[window][getLastWindow]msg: Get top window failed")); } return; } @@ -1341,8 +1342,8 @@ napi_value JsWindowManager::OnShiftAppWindowPointerEvent(napi_env env, napi_call } }; if (napi_status::napi_ok != napi_send_event(env, std::move(asyncTask), napi_eprio_high)) { - napiAsyncTask->Reject(env, - CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][shiftAppWindowPointerEvent]msg:send event failed")); } return result; } diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index 8f78407d4cff301b4c6f7d08f12b1321b8530439..cf3aa4fa1aabe3fefd9a341c461b05109b67a69b 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -1055,6 +1055,12 @@ napi_value NapiThrowError(napi_env env, WmErrorCode errCode) return NapiGetUndefined(env); } +napi_value NapiThrowError(napi_env env, WmErrorCode errCode, const std::string& msg) +{ + napi_throw(env, JsErrUtils::CreateJsError(env, errCode, msg)); + return NapiGetUndefined(env); +} + napi_valuetype GetType(napi_env env, napi_value value) { napi_valuetype res = napi_undefined; @@ -2332,7 +2338,8 @@ napi_value JsWindow::OnSetDialogBackGestureEnabled(napi_env env, napi_callback_i NapiAsyncTask::CompleteCallback complete = [weakToken, errCodePtr](napi_env env, NapiAsyncTask& task, int32_t status) { if (errCodePtr == nullptr) { - task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setDialogBackGestureEnabled]msg:System abnormal")); return; } if (*errCodePtr == WmErrorCode::WM_OK) { @@ -3689,14 +3696,16 @@ napi_value JsWindow::OnSetWindowFocusable(napi_env env, napi_callback_info info) auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { task.Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "Invalidate params.")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowFocusable]msg: Window is nullptr")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->SetFocusable(focusable)); if (ret == WmErrorCode::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, JsErrUtils::CreateJsError(env, ret, "Window set focusable failed")); + task.Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][setWindowFocusable]msg: Window set focusable failed")); } WLOGI("Window [%{public}u, %{public}s] set focusable end", weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); @@ -3752,13 +3761,15 @@ napi_value JsWindow::OnSetTopmost(napi_env env, napi_callback_info info) NapiAsyncTask::CompleteCallback complete = [weakToken, errCodePtr](napi_env env, NapiAsyncTask& task, int32_t status) { if (errCodePtr == nullptr) { - task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setTopmost]msg: System abnormal")); return; } if (*errCodePtr == WmErrorCode::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr, "Window set topmost failed")); + task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr, + "[window][setTopmost]msg: Window set topmost failed")); } }; napi_value result = nullptr; @@ -3962,7 +3973,7 @@ napi_value JsWindow::OnSetWakeUpScreen(napi_env env, napi_callback_info info) if (ret != WmErrorCode::WM_OK) { return NapiThrowError(env, ret); } - + WLOGI("Window [%{public}u, %{public}s] set wake up screen %{public}d end", windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), wakeUp); return NapiGetUndefined(env); @@ -4149,7 +4160,8 @@ napi_value JsWindow::OnSetTouchableAreas(napi_env env, napi_callback_info info) } if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_EVENT, "WindowToken_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setTouchableAreas]msg:window is null"); } Rect windowRect = windowToken_->GetRect(); std::vector touchableAreas; @@ -4163,7 +4175,8 @@ napi_value JsWindow::OnSetTouchableAreas(napi_env env, napi_callback_info info) auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { TLOGE(WmsLogTag::WMS_EVENT, "CompleteCallback window is nullptr"); - task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setTouchableAreas]msg:window is null")); return; } WMError ret = weakWindow->SetTouchHotAreas(touchableAreas); @@ -4458,18 +4471,21 @@ napi_value JsWindow::OnRaiseAboveTarget(napi_env env, napi_callback_info info) [weakToken, subWindowId, errCode](napi_env env, NapiAsyncTask& task, int32_t status) { auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { - task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][raiseAboveTarget]msg: Window is nullptr")); return; } if (errCode != WmErrorCode::WM_OK) { - task.Reject(env, JsErrUtils::CreateJsError(env, errCode, "Invalidate params.")); + task.Reject(env, JsErrUtils::CreateJsError(env, errCode, + "[window][raiseAboveTarget]msg: Invalidate params.")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->RaiseAboveTarget(subWindowId)); if (ret == WmErrorCode::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, JsErrUtils::CreateJsError(env, ret, "Window set raiseAboveTarget failed")); + task.Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][raiseAboveTarget]msg: Window set raiseAboveTarget failed")); } }; @@ -4487,36 +4503,42 @@ napi_value JsWindow::OnKeepKeyboardOnFocus(napi_env env, napi_callback_info info napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc < 1) { WLOGFE("Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][OnKeepKeyboardOnFocus]msg:argc is invalid"); } bool keepKeyboardFlag = false; napi_value nativeVal = argv[0]; if (nativeVal == nullptr) { WLOGFE("Failed to get parameter keepKeyboardFlag"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][OnKeepKeyboardOnFocus]msg:nativeVal is null"); } else { WmErrorCode errCode = WmErrorCode::WM_OK; CHECK_NAPI_RETCODE(errCode, WmErrorCode::WM_ERROR_INVALID_PARAM, napi_get_value_bool(env, nativeVal, &keepKeyboardFlag)); if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][OnKeepKeyboardOnFocus]msg:invalid nativeVal"); } } if (windowToken_ == nullptr) { WLOGFE("WindowToken_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][OnKeepKeyboardOnFocus]msg:WindowToken_ is null"); } if (!WindowHelper::IsSystemWindow(windowToken_->GetType()) && !WindowHelper::IsSubWindow(windowToken_->GetType())) { - WLOGFE("KeepKeyboardOnFocus is not allowed since window is not system window or app subwindow"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + WLOGFE("not allowed since window is not system window or app subwindow"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][OnKeepKeyboardOnFocus]msg:windowType is invalid"); } WmErrorCode ret = windowToken_->KeepKeyboardOnFocus(keepKeyboardFlag); if (ret != WmErrorCode::WM_OK) { - WLOGFE("Window KeepKeyboardOnFocus failed"); - return NapiThrowError(env, ret); + WLOGFE("failed"); + return NapiThrowError(env, ret, + "[window][OnKeepKeyboardOnFocus]msg:failed"); } WLOGI("Window [%{public}u, %{public}s] KeepKeyboardOnFocus end, keepKeyboardFlag = %{public}d", @@ -5032,14 +5054,16 @@ napi_value JsWindow::OnRaiseToAppTop(napi_env env, napi_callback_info info) auto window = weakToken.promote(); if (window == nullptr) { WLOGFE("window is nullptr"); - task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][raiseToAppTop]msg: Window is nullptr")); return; } WmErrorCode errCode = WM_JS_TO_ERROR_CODE_MAP.at(window->RaiseToAppTop()); if (errCode != WmErrorCode::WM_OK) { WLOGFE("raise window zorder failed"); - task.Reject(env, JsErrUtils::CreateJsError(env, errCode)); + task.Reject(env, JsErrUtils::CreateJsError(env, errCode, + "[window][raiseToAppTop]msg: Raise window zorder failed")); return; } task.Resolve(env, NapiGetUndefined(env)); @@ -5710,7 +5734,7 @@ napi_value JsWindow::OnSetHandwritingFlag(napi_env env, napi_callback_info info) [weakToken, isAddFlag, errCodePtr](napi_env env, NapiAsyncTask& task, int32_t status) { if (errCodePtr == nullptr) { task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "System abnormal.")); + "[window][setHandwritingFlag]msg:System abnormal.")); return; } if (*errCodePtr == WmErrorCode::WM_OK) { @@ -6809,13 +6833,15 @@ static void SetRequestFocusTask(NapiAsyncTask::ExecuteCallback& execute, NapiAsy }; complete = [weakToken, errCodePtr](napi_env env, NapiAsyncTask& task, int32_t status) { if (errCodePtr == nullptr) { - task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][requestFocus]msg: System abnormal")); return; } if (*errCodePtr == WmErrorCode::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr, "JsWindow::OnRequestFocus failed")); + task.Reject(env, JsErrUtils::CreateJsError(env, *errCodePtr, + "[window][requestFocus]msg: Request focus failed")); } }; } @@ -7198,7 +7224,8 @@ napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_inf auto window = weakToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s: window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setExclusivelyHighlighted]msg: Window is nullptr")); return; } WMError ret = window->SetExclusivelyHighlighted(exclusivelyHighlighted); @@ -7206,14 +7233,15 @@ napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_inf task->Resolve(env, NapiGetUndefined(env)); } else { WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); - task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Set exclusively highlighted failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, + "[window][setExclusivelyHighlighted]msg: Set exclusively highlighted failed")); } TLOGNI(WmsLogTag::WMS_FOCUS, "%{public}s: end, window: [%{public}u, %{public}s]", where, window->GetWindowId(), window->GetWindowName().c_str()); }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - napiAsyncTask->Reject(env, CreateJsError(env, - static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), + "[window][setExclusivelyHighlighted]msg: Failed to send event")); } return result; } diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.h b/interfaces/kits/napi/window_runtime/window_napi/js_window.h index e6c294f49513a2afbe7b7cb9fd945da7fe8d8e16..979b923cdb0e702cb288094508ac3b049325a9c2 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -39,6 +39,7 @@ napi_value NapiGetUndefined(napi_env env); napi_valuetype GetType(napi_env env, napi_value value); bool NapiIsCallable(napi_env env, napi_value value); napi_value NapiThrowError(napi_env env, WmErrorCode errCode); +napi_value NapiThrowError(napi_env env, WmErrorCode errCode, const std::string& msg); class JsWindow final { public: explicit JsWindow(const sptr& window);