From 9b515bbab9a8eab73bee1b8d777fd0c999bc0a02 Mon Sep 17 00:00:00 2001 From: Radu Date: Mon, 26 Aug 2024 15:12:21 +0300 Subject: [PATCH 1/2] Fix duplicate output; Add notification for success --- l10n/bundle.l10n.es.json | 3 ++- l10n/bundle.l10n.pt.json | 3 ++- l10n/bundle.l10n.ru.json | 3 ++- l10n/bundle.l10n.zh-CN.json | 3 ++- src/espIdf/setTarget/setTargetInIdf.ts | 8 +++++++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/l10n/bundle.l10n.es.json b/l10n/bundle.l10n.es.json index fd93c17b0..46b46505a 100644 --- a/l10n/bundle.l10n.es.json +++ b/l10n/bundle.l10n.es.json @@ -182,5 +182,6 @@ "Open ESP-IDF Terminal": "Abrir terminal ESP-IDF", "Doctor Command": "Comando médico", "Execute Custom Task": "Ejecutar tarea personalizada", - "Wait for ESP-IDF build or flash to finish": "Espere a que finalice la compilación o la actualización de ESP-IDF" + "Wait for ESP-IDF build or flash to finish": "Espere a que finalice la compilación o la actualización de ESP-IDF", + "Target {0} Set Successfully": "Objetivo {0} configurado con éxito." } diff --git a/l10n/bundle.l10n.pt.json b/l10n/bundle.l10n.pt.json index a764290a2..4495be034 100644 --- a/l10n/bundle.l10n.pt.json +++ b/l10n/bundle.l10n.pt.json @@ -182,5 +182,6 @@ "Open ESP-IDF Terminal": "Abra o terminal ESP-IDF", "Doctor Command": "Comando Médico", "Execute Custom Task": "Executar tarefa personalizada", - "Wait for ESP-IDF build or flash to finish": "Aguarde a conclusão da compilação ou flash do ESP-IDF" + "Wait for ESP-IDF build or flash to finish": "Aguarde a conclusão da compilação ou flash do ESP-IDF", + "Target {0} Set Successfully": "Alvo {0} definido com sucesso." } diff --git a/l10n/bundle.l10n.ru.json b/l10n/bundle.l10n.ru.json index 28b20f0a2..d5dae1aa6 100644 --- a/l10n/bundle.l10n.ru.json +++ b/l10n/bundle.l10n.ru.json @@ -182,5 +182,6 @@ "Open ESP-IDF Terminal": "Открыть терминал ESP-IDF", "Doctor Command": "Доктор Команда", "Execute Custom Task": "Выполнить пользовательскую задачу", - "Wait for ESP-IDF build or flash to finish": "Подождите завершения сборки или прошивки ESP-IDF." + "Wait for ESP-IDF build or flash to finish": "Подождите завершения сборки или прошивки ESP-IDF.", + "Target {0} Set Successfully": "Цель {0} успешно установлена." } diff --git a/l10n/bundle.l10n.zh-CN.json b/l10n/bundle.l10n.zh-CN.json index 81cd8478e..80a23408a 100644 --- a/l10n/bundle.l10n.zh-CN.json +++ b/l10n/bundle.l10n.zh-CN.json @@ -182,5 +182,6 @@ "Open ESP-IDF Terminal": "打开 ESP-IDF 终端", "Doctor Command": "医生指挥", "Execute Custom Task": "执行自定义任务", - "Wait for ESP-IDF build or flash to finish": "等待 ESP-IDF 构建或刷新完成" + "Wait for ESP-IDF build or flash to finish": "等待 ESP-IDF 构建或刷新完成", + "Target {0} Set Successfully": "目标 {0} 设置成功" } diff --git a/src/espIdf/setTarget/setTargetInIdf.ts b/src/espIdf/setTarget/setTargetInIdf.ts index a86e09897..d756020ce 100644 --- a/src/espIdf/setTarget/setTargetInIdf.ts +++ b/src/espIdf/setTarget/setTargetInIdf.ts @@ -29,6 +29,7 @@ import { import { ConfserverProcess } from "../menuconfig/confServerProcess"; import { IdfTarget } from "./getTargets"; import { getVirtualEnvPythonPath } from "../../pythonManager"; +import * as vscode from "vscode"; export async function setTargetInIDF( workspaceFolder: WorkspaceFolder, @@ -76,6 +77,11 @@ export async function setTargetInIDF( env: modifiedEnv, }); Logger.info(setTargetResult.toString()); - OutputChannel.append(setTargetResult.toString()); + const msg = vscode.l10n.t( + "Target {0} Set Successfully.", + selectedTarget.target.toLocaleUpperCase() + ); + OutputChannel.appendLineAndShow(msg, "Set Target"); + Logger.infoNotify(msg); setCCppPropertiesJsonCompilerPath(workspaceFolder.uri); } From 1fab9da5bc9bb2d9ed80a6a50d512eefa5b453e6 Mon Sep 17 00:00:00 2001 From: Radu Date: Mon, 26 Aug 2024 16:05:07 +0300 Subject: [PATCH 2/2] Fix error handling for unsuccessful attempt Fix lint Fix duplication --- l10n/bundle.l10n.es.json | 3 ++- l10n/bundle.l10n.pt.json | 3 ++- l10n/bundle.l10n.ru.json | 3 ++- l10n/bundle.l10n.zh-CN.json | 3 ++- src/espIdf/setTarget/index.ts | 22 ++++++++++++------- src/espIdf/setTarget/setTargetInIdf.ts | 30 +++++++++++++++----------- 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/l10n/bundle.l10n.es.json b/l10n/bundle.l10n.es.json index 46b46505a..2be741f1d 100644 --- a/l10n/bundle.l10n.es.json +++ b/l10n/bundle.l10n.es.json @@ -183,5 +183,6 @@ "Doctor Command": "Comando médico", "Execute Custom Task": "Ejecutar tarea personalizada", "Wait for ESP-IDF build or flash to finish": "Espere a que finalice la compilación o la actualización de ESP-IDF", - "Target {0} Set Successfully": "Objetivo {0} configurado con éxito." + "Target {0} Set Successfully.": "Objetivo {0} configurado con éxito.", + "Unknown error occurred while setting IDF target.": "Ocurrió un error desconocido al configurar el objetivo IDF." } diff --git a/l10n/bundle.l10n.pt.json b/l10n/bundle.l10n.pt.json index 4495be034..a064300a0 100644 --- a/l10n/bundle.l10n.pt.json +++ b/l10n/bundle.l10n.pt.json @@ -183,5 +183,6 @@ "Doctor Command": "Comando Médico", "Execute Custom Task": "Executar tarefa personalizada", "Wait for ESP-IDF build or flash to finish": "Aguarde a conclusão da compilação ou flash do ESP-IDF", - "Target {0} Set Successfully": "Alvo {0} definido com sucesso." + "Target {0} Set Successfully.": "Alvo {0} definido com sucesso.", + "Unknown error occurred while setting IDF target.": "Ocorreu um erro desconhecido ao definir o alvo IDF." } diff --git a/l10n/bundle.l10n.ru.json b/l10n/bundle.l10n.ru.json index d5dae1aa6..75317990b 100644 --- a/l10n/bundle.l10n.ru.json +++ b/l10n/bundle.l10n.ru.json @@ -183,5 +183,6 @@ "Doctor Command": "Доктор Команда", "Execute Custom Task": "Выполнить пользовательскую задачу", "Wait for ESP-IDF build or flash to finish": "Подождите завершения сборки или прошивки ESP-IDF.", - "Target {0} Set Successfully": "Цель {0} успешно установлена." + "Target {0} Set Successfully.": "Цель {0} успешно установлена.", + "Unknown error occurred while setting IDF target.": "Произошла неизвестная ошибка при установке цели IDF." } diff --git a/l10n/bundle.l10n.zh-CN.json b/l10n/bundle.l10n.zh-CN.json index 80a23408a..e6ecd905d 100644 --- a/l10n/bundle.l10n.zh-CN.json +++ b/l10n/bundle.l10n.zh-CN.json @@ -183,5 +183,6 @@ "Doctor Command": "医生指挥", "Execute Custom Task": "执行自定义任务", "Wait for ESP-IDF build or flash to finish": "等待 ESP-IDF 构建或刷新完成", - "Target {0} Set Successfully": "目标 {0} 设置成功" + "Target {0} Set Successfully.": "目标 {0} 设置成功", + "Unknown error occurred while setting IDF target.": "设置 IDF 目标时发生未知错误" } diff --git a/src/espIdf/setTarget/index.ts b/src/espIdf/setTarget/index.ts index 5888bc10f..11b04b09f 100644 --- a/src/espIdf/setTarget/index.ts +++ b/src/espIdf/setTarget/index.ts @@ -22,6 +22,7 @@ import { ProgressLocation, WorkspaceFolder, window, + l10n, } from "vscode"; import { NotificationMode, @@ -34,7 +35,10 @@ import { getBoards, getOpenOcdScripts } from "../openOcd/boardConfiguration"; import { getTargetsFromEspIdf } from "./getTargets"; import { setTargetInIDF } from "./setTargetInIdf"; -export async function setIdfTarget(placeHolderMsg: string, workspaceFolder: WorkspaceFolder) { +export async function setIdfTarget( + placeHolderMsg: string, + workspaceFolder: WorkspaceFolder +) { const configurationTarget = ConfigurationTarget.WorkspaceFolder; if (!workspaceFolder) { return; @@ -98,17 +102,19 @@ export async function setIdfTarget(placeHolderMsg: string, workspaceFolder: Work workspaceFolder.uri ); } - await setTargetInIDF(workspaceFolder, selectedTarget); } catch (err) { const errMsg = - err && err.message ? err.message : "Error running idf.py set-target"; - if (errMsg.indexOf("are satisfied") > -1) { - Logger.info(err.message.toString()); - OutputChannel.append(err.message.toString()); + err instanceof Error + ? err.message + : l10n.t("Unknown error occurred while setting IDF target."); + + if (errMsg.includes("are satisfied")) { + Logger.info(errMsg); + OutputChannel.appendLine(errMsg); } else { - Logger.errorNotify(err, err, "setIdfTarget"); - OutputChannel.append(err); + Logger.errorNotify(errMsg, err, "setIdfTarget"); + OutputChannel.appendLine(errMsg); } } } diff --git a/src/espIdf/setTarget/setTargetInIdf.ts b/src/espIdf/setTarget/setTargetInIdf.ts index d756020ce..04928600c 100644 --- a/src/espIdf/setTarget/setTargetInIdf.ts +++ b/src/espIdf/setTarget/setTargetInIdf.ts @@ -72,16 +72,22 @@ export async function setTargetInIDF( setTargetArgs.push("set-target", selectedTarget.target); const pythonBinPath = await getVirtualEnvPythonPath(workspaceFolder.uri); - const setTargetResult = await spawn(pythonBinPath, setTargetArgs, { - cwd: workspaceFolder.uri.fsPath, - env: modifiedEnv, - }); - Logger.info(setTargetResult.toString()); - const msg = vscode.l10n.t( - "Target {0} Set Successfully.", - selectedTarget.target.toLocaleUpperCase() - ); - OutputChannel.appendLineAndShow(msg, "Set Target"); - Logger.infoNotify(msg); - setCCppPropertiesJsonCompilerPath(workspaceFolder.uri); + try { + const setTargetResult = await spawn(pythonBinPath, setTargetArgs, { + cwd: workspaceFolder.uri.fsPath, + env: modifiedEnv, + }); + Logger.info(setTargetResult.toString()); + const msg = vscode.l10n.t( + "Target {0} Set Successfully.", + selectedTarget.target.toLocaleUpperCase() + ); + OutputChannel.appendLineAndShow(msg, "Set Target"); + Logger.infoNotify(msg); + setCCppPropertiesJsonCompilerPath(workspaceFolder.uri); + } catch (error) { + throw new Error( + `Failed to set target ${selectedTarget.target}: ${error.message}.` + ); + } }