From 83664517b0d85896bbcdef35469fb224a29b3fd4 Mon Sep 17 00:00:00 2001 From: wangchuan Date: Mon, 1 Sep 2025 20:58:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=94=E5=9B=9E=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BF=A1=E6=81=AF=E5=90=88=E5=85=A5=E5=95=86=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchuan --- .../window_runtime/window_napi/js_window.cpp | 157 +++++++++++------- 1 file changed, 96 insertions(+), 61 deletions(-) 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 b504513144..f5afcd8ff8 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -1365,14 +1365,15 @@ napi_value JsWindow::OnRecover(napi_env env, napi_callback_info info) if (weakWindow == nullptr) { WLOGFE("window is nullptr or get invalid param"); task.Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][recover]msg: Window is nullptr")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(weakWindow->Recover(1)); if (ret == WmErrorCode::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, JsErrUtils::CreateJsError(env, ret, "Window recover failed")); + task.Reject(env, JsErrUtils::CreateJsError(env, ret, "[window][recover]msg: Failed")); } WLOGI("Window [%{public}u] recover end, ret = %{public}d", weakWindow->GetWindowId(), ret); }; @@ -1502,7 +1503,8 @@ napi_value JsWindow::OnMoveWindowTo(napi_env env, napi_callback_info info) errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowTo]msg: Invaild param"); } // 2: params num; 2: index of callback napi_value lastParam = (argc <= 2) ? nullptr : @@ -1514,21 +1516,24 @@ napi_value JsWindow::OnMoveWindowTo(napi_env env, napi_callback_info info) auto window = windowToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT, "%{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][moveWindowTo]msg: Window is nullptr")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->MoveTo(x, y)); if (ret == WmErrorCode::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window move failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, + "[window][moveWindowTo]msg: Failed")); } TLOGNI(WmsLogTag::WMS_LAYOUT, "%{public}s: Window [%{public}u, %{public}s] move end, ret = %{public}d", where, window->GetWindowId(), window->GetWindowName().c_str(), ret); }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][moveWindowTo]msg: Failed to send event")); } return result; } @@ -1589,7 +1594,8 @@ napi_value JsWindow::OnMoveWindowToAsync(napi_env env, napi_callback_info info) errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToAsync]msg: Invalid param"); } wptr weakToken(windowToken_); @@ -1663,7 +1669,8 @@ napi_value JsWindow::OnMoveWindowToGlobal(napi_env env, napi_callback_info info) errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][moveWindowToGlobal]msg: Invalid param"); } wptr weakToken(windowToken_); @@ -1697,7 +1704,8 @@ napi_value JsWindow::OnGetGlobalScaledRect(napi_env env, napi_callback_info info napi_value globalScaledRectObj = GetRectAndConvertToJsValue(env, globalScaledRect); if (globalScaledRectObj == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "globalScaledRectObj is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getGlobalScaledRect]msg: GlobalScaledRectObj is nullptr"); } return globalScaledRectObj; } @@ -1734,28 +1742,30 @@ napi_value JsWindow::OnResize(napi_env env, napi_callback_info info) auto asyncTask = [windowToken = wptr(windowToken_), errCode, width, height, env, task = napiAsyncTask, where = __func__] { if (errCode != WMError::WM_OK) { - task->Reject(env, JsErrUtils::CreateJsError(env, errCode)); + task->Reject(env, JsErrUtils::CreateJsError(env, errCode, "[window][resize]msg: Invalid param")); TLOGNE(WmsLogTag::WMS_LAYOUT, "%{public}s: invalid param", where); return; } auto window = windowToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT, "%{public}s: window is nullptr", where); - task->Reject(env, JsErrUtils::CreateJsError(env, WMError::WM_ERROR_NULLPTR)); + task->Reject(env, JsErrUtils::CreateJsError(env, WMError::WM_ERROR_NULLPTR, + "[window][resize]msg: Window is nullptr")); return; } WMError ret = window->Resize(static_cast(width), static_cast(height)); if (ret == WMError::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window resize failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, "[window][resize]msg: Failed")); } TLOGND(WmsLogTag::WMS_LAYOUT, "%{public}s: Window [%{public}u, %{public}s] resize end, ret = %{public}d", where, window->GetWindowId(), window->GetWindowName().c_str(), ret); }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][resize]msg: Failed to send event")); } return result; } @@ -1879,7 +1889,8 @@ napi_value JsWindow::OnResizeWindowAsync(napi_env env, napi_callback_info info) errCode = WmErrorCode::WM_ERROR_INVALID_PARAM; } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][resizeWindowAsync]msg: Invalid param"); } wptr weakToken(windowToken_); @@ -1959,7 +1970,8 @@ napi_value JsWindow::OnSetWindowMode(napi_env env, napi_callback_info info) { if (!Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) { TLOGE(WmsLogTag::WMS_LAYOUT, "set window mode permission denied!"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP); + return NapiThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP, + "[window][setWindowMode]msg: Permission denied"); } WmErrorCode errCode = WmErrorCode::WM_OK; size_t argc = 4; @@ -1988,7 +2000,7 @@ napi_value JsWindow::OnSetWindowMode(napi_env env, napi_callback_info info) } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, "[window][setWindowMode]msg: Invalid param"); } napi_value lastParam = (argc == 1) ? nullptr : ((argv[1] != nullptr && GetType(env, argv[1]) == napi_function) ? argv[1] : nullptr); @@ -1999,21 +2011,23 @@ napi_value JsWindow::OnSetWindowMode(napi_env env, napi_callback_info info) auto window = windowToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT, "%{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][setWindowMode]msg: Window is nullptr")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->SetWindowMode(winMode)); if (ret == WmErrorCode::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window set mode failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, "[window][setWindowMode]msg: Failed")); } TLOGNI(WmsLogTag::WMS_LAYOUT, "%{public}s: Window [%{public}u, %{public}s] set mode end, ret = %{public}d", where, window->GetWindowId(), window->GetWindowName().c_str(), ret); }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { napiAsyncTask->Reject(env, - JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "failed to send event")); + JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setWindowMode]msg: Failed to send event")); } return result; } @@ -4161,12 +4175,14 @@ napi_value JsWindow::OnSetResizeByDragEnabled(napi_env env, napi_callback_info i if (weakWindow == nullptr) { WLOGFE("window is nullptr"); wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(WMError::WM_ERROR_NULLPTR); - task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode)); + task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, + "[window][setResizeByDragEnabled]msg: Window is nullptr")); return; } if (errCode != WMError::WM_OK) { wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(errCode); - task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Invalidate params.")); + task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, + "[window][setResizeByDragEnabled]msg: Invalid param")); return; } WMError ret = weakWindow->SetResizeByDragEnabled(dragEnabled); @@ -4174,7 +4190,8 @@ napi_value JsWindow::OnSetResizeByDragEnabled(napi_env env, napi_callback_info i task.Resolve(env, NapiGetUndefined(env)); } else { wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); - task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "set dragEnabled failed")); + task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, + "[window][setResizeByDragEnabled]msg: Failed")); } WLOGI("Window [%{public}u, %{public}s] set dragEnabled end", weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); @@ -4861,7 +4878,8 @@ napi_value JsWindow::OnSetForbidSplitMove(napi_env env, napi_callback_info info) } } if (errCode == WmErrorCode::WM_ERROR_INVALID_PARAM) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setForbidSplitMove]msg: Invalid param"); } wptr weakToken(windowToken_); NapiAsyncTask::CompleteCallback complete = @@ -4869,7 +4887,7 @@ napi_value JsWindow::OnSetForbidSplitMove(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.")); + "[window][setForbidSplitMove]msg: Invalid param")); return; } WmErrorCode ret; @@ -4883,7 +4901,7 @@ napi_value JsWindow::OnSetForbidSplitMove(napi_env env, napi_callback_info info) if (ret == WmErrorCode::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, JsErrUtils::CreateJsError(env, ret, "Window OnSetForbidSplitMove failed.")); + task.Reject(env, JsErrUtils::CreateJsError(env, ret, "[window][setForbidSplitMove]msg: Failed")); } }; napi_value lastParam = (argc <= 1) ? nullptr : @@ -5690,12 +5708,14 @@ napi_value JsWindow::OnSetAspectRatio(napi_env env, napi_callback_info info) if (windowToken_ == nullptr) { WLOGFE("WindowToken_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][setAspectRatio]msg: Window is nullptr"); } if (!WindowHelper::IsMainWindow(windowToken_->GetType())) { WLOGFE("[NAPI]SetAspectRatio is not allowed since window is main window"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][setAspectRatio]msg: SetAspectRatio is only allowed for the main window"); } double aspectRatio = 0.0; @@ -5710,7 +5730,7 @@ napi_value JsWindow::OnSetAspectRatio(napi_env env, napi_callback_info info) } if (errCode == WMError::WM_ERROR_INVALID_PARAM || aspectRatio <= 0.0) { - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, "[window][setAspectRatio]msg: Invalid param"); } wptr weakToken(windowToken_); @@ -5719,7 +5739,7 @@ napi_value JsWindow::OnSetAspectRatio(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, - "OnSetAspectRatio failed.")); + "[window][setAspectRatio]msg: Failed")); return; } WMError ret = weakWindow->SetAspectRatio(aspectRatio); @@ -5727,7 +5747,7 @@ napi_value JsWindow::OnSetAspectRatio(napi_env env, napi_callback_info info) task.Resolve(env, NapiGetUndefined(env)); } else { task.Reject(env, JsErrUtils::CreateJsError(env, WM_JS_TO_ERROR_CODE_MAP.at(ret), - "SetAspectRatio failed.")); + "[window][setAspectRatio]msg: Failed")); } WLOGI("[NAPI]Window [%{public}u, %{public}s] set aspect ratio end, ret = %{public}d", weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); @@ -5747,17 +5767,20 @@ napi_value JsWindow::OnResetAspectRatio(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc > 1) { WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][resetAspectRatio]msg: The number of parameters is invalid"); } if (windowToken_ == nullptr) { WLOGFE("WindowToken_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][resetAspectRatio]msg: Window is nullptr"); } if (!WindowHelper::IsMainWindow(windowToken_->GetType())) { WLOGFE("[NAPI]ResetAspectRatio is not allowed since window is main window"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][resetAspectRatio]msg: Only support main window"); } wptr weakToken(windowToken_); @@ -5767,14 +5790,14 @@ napi_value JsWindow::OnResetAspectRatio(napi_env env, napi_callback_info info) if (weakWindow == nullptr) { task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "OnResetAspectRatio failed.")); + "[window][resetAspectRatio]msg: Failed")); return; } WMError ret = weakWindow->ResetAspectRatio(); if (ret == WMError::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, JsErrUtils::CreateJsError(env, ret, "ResetAspectRatio failed.")); + task.Reject(env, JsErrUtils::CreateJsError(env, ret, "[window][resetAspectRatio]msg: Failed")); } WLOGI("[NAPI]Window [%{public}u, %{public}s] reset aspect ratio end, ret = %{public}d", weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); @@ -5815,7 +5838,7 @@ napi_value JsWindow::OnMinimize(napi_env env, napi_callback_info info) errCode = (weakWindow == nullptr) ? WmErrorCode::WM_ERROR_STATE_ABNORMALLY : errCode; if (errCode != WmErrorCode::WM_OK) { task.Reject(env, - JsErrUtils::CreateJsError(env, errCode, "OnMinimize failed.")); + JsErrUtils::CreateJsError(env, errCode, "[window][minimize]msg: Failed")); WLOGFE("window is nullptr"); return; } @@ -5824,7 +5847,7 @@ napi_value JsWindow::OnMinimize(napi_env env, napi_callback_info info) task.Resolve(env, NapiGetUndefined(env)); } else { WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); - task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Minimize failed.")); + task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "[window][minimize]msg: Failed")); } WLOGI("[NAPI]Window [%{public}u, %{public}s] minimize end, ret = %{public}d", weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); @@ -5843,7 +5866,7 @@ napi_value JsWindow::OnMaximize(napi_env env, napi_callback_info info) WmErrorCode errCode = WmErrorCode::WM_OK; if (windowToken_ == nullptr) { WLOGFE("WindowToken_ is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "[window][minimize]msg: Window is nullptr"); } size_t argc = 4; napi_value argv[4] = {nullptr}; @@ -5851,7 +5874,8 @@ napi_value JsWindow::OnMaximize(napi_env env, napi_callback_info info) wptr weakToken(windowToken_); if (!WindowHelper::IsMainWindow(weakToken->GetType())) { WLOGFE("[NAPI] maximize interface only support main Window"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "[window][minimize]msg: Only support main window"); } MaximizePresentation presentation = MaximizePresentation::ENTER_IMMERSIVE; if (argc == 1) { @@ -5876,7 +5900,7 @@ napi_value JsWindow::OnMaximize(napi_env env, napi_callback_info info) task.Resolve(env, NapiGetUndefined(env)); } else { WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); - task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Maximize failed.")); + task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "[window][minimize]msg: Failed")); } }; @@ -6022,25 +6046,28 @@ napi_value JsWindow::OnEnableDrag(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc < 1 || argv[INDEX_ZERO] == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][enableDrag]msg: The number of paramters is invalid"); } if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "window is nullptr!"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][enableDrag]msg: Window is nullptr"); } if (!Permission::IsSystemCalling()) { TLOGE(WmsLogTag::WMS_LAYOUT, "permission denied!"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP); + return NapiThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP, "[window][enableDrag]msg: Permission denied"); } if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) { TLOGE(WmsLogTag::WMS_LAYOUT, "is not allowed since window is not system window"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, "[window][enableDrag]msg: Failed"); } bool enableDrag = false; if (!ConvertFromJsValue(env, argv[INDEX_ZERO], enableDrag)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert parameter from jsValue"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][enableDrag]msg: Failed to convert parameter to enableDrag"); } std::shared_ptr errCodePtr = std::make_shared(WmErrorCode::WM_OK); NapiAsyncTask::ExecuteCallback execute = @@ -6061,17 +6088,20 @@ napi_value JsWindow::OnSetWindowLimits(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc < 1 || argv[INDEX_ZERO] == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setWindowLimits]msg: The number of paramters is invalid"); } WindowLimits windowLimits; if (!ParseWindowLimits(env, argv[INDEX_ZERO], windowLimits)) { TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to convert object to windowLimits"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setWindowLimits]msg: Failed to convert parameter to windowLimits"); } if (windowLimits.maxWidth_ < 0 || windowLimits.maxHeight_ < 0 || windowLimits.minWidth_ < 0 || windowLimits.minHeight_ < 0) { TLOGE(WmsLogTag::WMS_LAYOUT, "Width or height should be greater than or equal to 0"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, + "[window][setWindowLimits]msg: Width or height should be greater than or equal to 0"); } napi_value lastParam = (argc <= 1) ? nullptr : (GetType(env, argv[1]) == napi_function ? argv[1] : nullptr); napi_value result = nullptr; @@ -6081,7 +6111,8 @@ napi_value JsWindow::OnSetWindowLimits(napi_env env, napi_callback_info info) auto window = windowToken.promote(); if (window == nullptr) { TLOGNE(WmsLogTag::WMS_LAYOUT, "%{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][setWindowLimits]msg: Window is nullptr")); return; } WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->SetWindowLimits(windowLimits)); @@ -6089,12 +6120,12 @@ napi_value JsWindow::OnSetWindowLimits(napi_env env, napi_callback_info info) auto objValue = GetWindowLimitsAndConvertToJsValue(env, windowLimits); if (objValue == nullptr) { task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, - "Window set window limits failed")); + "[window][setWindowLimits]msg: Failed")); } else { task->Resolve(env, objValue); } } else { - task->Reject(env, JsErrUtils::CreateJsError(env, ret, "Window set window limits failed")); + task->Reject(env, JsErrUtils::CreateJsError(env, ret, "[window][setWindowLimits]msg: Failed")); } }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { @@ -6112,19 +6143,20 @@ napi_value JsWindow::OnGetWindowLimits(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc > 1) { TLOGE(WmsLogTag::WMS_LAYOUT, "Argc is invalid: %{public}zu", argc); - return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM, "[window][getWindowLimits]msg: Invalid param"); } wptr weakToken(windowToken_); auto window = weakToken.promote(); if (window == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowLimits]msg: Window is nullptr"); } WindowLimits windowLimits; WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->GetWindowLimits(windowLimits)); if (ret != WmErrorCode::WM_OK) { - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][getWindowLimits]msg: Failed"); } auto objValue = GetWindowLimitsAndConvertToJsValue(env, windowLimits); TLOGI(WmsLogTag::WMS_LAYOUT, "Window [%{public}u, %{public}s] get window limits end", @@ -6132,7 +6164,7 @@ napi_value JsWindow::OnGetWindowLimits(napi_env env, napi_callback_info info) if (objValue != nullptr) { return objValue; } else { - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "[window][getWindowLimits]msg: Failed"); } } @@ -6644,13 +6676,14 @@ napi_value JsWindow::OnGetWindowStatus(napi_env env, napi_callback_info info) auto window = windowToken_; if (window == nullptr) { TLOGE(WmsLogTag::DEFAULT, "window is nullptr"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowStatus]msg: Window is nullptr"); } WindowStatus windowStatus; WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->GetWindowStatus(windowStatus)); if (ret != WmErrorCode::WM_OK) { TLOGE(WmsLogTag::DEFAULT, "get window status failed, ret = %{public}d", ret); - return NapiThrowError(env, ret); + return NapiThrowError(env, ret, "[window][getWindowStatus]msg: Failed"); } auto objValue = CreateJsValue(env, windowStatus); if (objValue != nullptr) { @@ -6659,7 +6692,8 @@ napi_value JsWindow::OnGetWindowStatus(napi_env env, napi_callback_info info) return objValue; } else { TLOGE(WmsLogTag::DEFAULT, "create js value windowStatus failed"); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][getWindowStatus]msg: Failed to create js windowStatus"); } } @@ -6908,7 +6942,8 @@ napi_value JsWindow::OnStartMoving(napi_env env, napi_callback_info info) { if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_LAYOUT, "windowToken is nullptr."); - return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "[window][startMoving]msg: Window is nullptr"); } std::shared_ptr err = std::make_shared(WmErrorCode::WM_OK); const char* const funcName = __func__; @@ -6936,13 +6971,13 @@ napi_value JsWindow::OnStartMoving(napi_env env, napi_callback_info info) NapiAsyncTask::CompleteCallback complete = [err](napi_env env, NapiAsyncTask& task, int32_t status) { if (err == nullptr) { task.Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), - "System abnormal.")); + "[window][startMoving]msg: Failed")); return; } if (*err == WmErrorCode::WM_OK) { task.Resolve(env, NapiGetUndefined(env)); } else { - task.Reject(env, CreateJsError(env, static_cast(*err), "Move window failed.")); + task.Reject(env, CreateJsError(env, static_cast(*err), "[window][startMoving]msg: Failed")); } }; napi_value result = nullptr; -- Gitee