From 12ea3b6721fde27bb457fecac2bb94b99e435a90 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Thu, 26 Oct 2023 21:04:08 +0200 Subject: [PATCH] Do not log unknown operations as an error for backward/foward compatibility --- cpp/piscsi/command_context.cpp | 8 +++++++- cpp/piscsi/localizer.cpp | 12 ++++++------ cpp/piscsi/piscsi_core.cpp | 4 ++-- cpp/piscsi/piscsi_executor.cpp | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cpp/piscsi/command_context.cpp b/cpp/piscsi/command_context.cpp index 8ed3718d..ab4eeac4 100644 --- a/cpp/piscsi/command_context.cpp +++ b/cpp/piscsi/command_context.cpp @@ -60,7 +60,13 @@ bool CommandContext::ReturnLocalizedError(LocalizationKey key, PbErrorCode error const string& arg2, const string& arg3) const { // For the logfile always use English - spdlog::error(localizer.Localize(key, "en", arg1, arg2, arg3)); + // Do not log unknown operations as an error for backward/foward compatibility with old/new clients + if (error_code == PbErrorCode::UNKNOWN_OPERATION) { + spdlog::trace(localizer.Localize(key, "en", arg1, arg2, arg3)); + } + else { + spdlog::error(localizer.Localize(key, "en", arg1, arg2, arg3)); + } return ReturnStatus(false, localizer.Localize(key, locale, arg1, arg2, arg3), error_code, false); } diff --git a/cpp/piscsi/localizer.cpp b/cpp/piscsi/localizer.cpp index 17c92034..1ac8f5f7 100644 --- a/cpp/piscsi/localizer.cpp +++ b/cpp/piscsi/localizer.cpp @@ -22,12 +22,12 @@ Localizer::Localizer() Add(LocalizationKey::ERROR_AUTHENTICATION, "es", "Fallo de autentificación"); Add(LocalizationKey::ERROR_AUTHENTICATION, "zh", "认证失败"); - Add(LocalizationKey::ERROR_OPERATION, "en", "Unknown operation"); - Add(LocalizationKey::ERROR_OPERATION, "de", "Unbekannte Operation"); - Add(LocalizationKey::ERROR_OPERATION, "sv", "Okänd operation"); - Add(LocalizationKey::ERROR_OPERATION, "fr", "Opération inconnue"); - Add(LocalizationKey::ERROR_OPERATION, "es", "Operación desconocida"); - Add(LocalizationKey::ERROR_OPERATION, "zh", "未知操作"); + Add(LocalizationKey::ERROR_OPERATION, "en", "Unknown operation: %1"); + Add(LocalizationKey::ERROR_OPERATION, "de", "Unbekannte Operation: %1"); + Add(LocalizationKey::ERROR_OPERATION, "sv", "Okänd operation: %1"); + Add(LocalizationKey::ERROR_OPERATION, "fr", "Opération inconnue: %1"); + Add(LocalizationKey::ERROR_OPERATION, "es", "Operación desconocida: %1"); + Add(LocalizationKey::ERROR_OPERATION, "zh", "未知操作: %1"); Add(LocalizationKey::ERROR_LOG_LEVEL, "en", "Invalid log level '%1'"); Add(LocalizationKey::ERROR_LOG_LEVEL, "de", "Ungültiger Log-Level '%1'"); diff --git a/cpp/piscsi/piscsi_core.cpp b/cpp/piscsi/piscsi_core.cpp index 083a5303..0493b5d9 100644 --- a/cpp/piscsi/piscsi_core.cpp +++ b/cpp/piscsi/piscsi_core.cpp @@ -323,9 +323,9 @@ bool Piscsi::ExecuteCommand(const CommandContext& context) } if (!PbOperation_IsValid(operation)) { - spdlog::error("Received unknown command with operation opcode " + to_string(operation)); + spdlog::trace("Ignored unknown command with operation opcode " + to_string(operation)); - return context.ReturnLocalizedError(LocalizationKey::ERROR_OPERATION, UNKNOWN_OPERATION); + return context.ReturnLocalizedError(LocalizationKey::ERROR_OPERATION, UNKNOWN_OPERATION, to_string(operation)); } spdlog::trace("Received " + PbOperation_Name(operation) + " command"); diff --git a/cpp/piscsi/piscsi_executor.cpp b/cpp/piscsi/piscsi_executor.cpp index cfe069d6..fcb43db8 100644 --- a/cpp/piscsi/piscsi_executor.cpp +++ b/cpp/piscsi/piscsi_executor.cpp @@ -79,7 +79,7 @@ bool PiscsiExecutor::ProcessDeviceCmd(const CommandContext& context, const PbDev break; default: - return context.ReturnLocalizedError(LocalizationKey::ERROR_OPERATION); + return context.ReturnLocalizedError(LocalizationKey::ERROR_OPERATION, to_string(operation)); } return true;