From 53601b5c71f8e39b7ab051970473a6a105736397 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Wed, 6 Sep 2023 01:43:20 +0900 Subject: [PATCH] =?UTF-8?q?C=20API=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E3=82=92`tracing::error!`=E3=81=AB=E3=81=99?= =?UTF-8?q?=E3=82=8B=20(#600)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 2 ++ crates/voicevox_core_c_api/Cargo.toml | 2 ++ crates/voicevox_core_c_api/src/helpers.rs | 10 +++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f304e58c..871df23ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4198,6 +4198,7 @@ dependencies = [ "duct", "easy-ext", "inventory", + "itertools", "libc", "libloading", "libtest-mimic", @@ -4215,6 +4216,7 @@ dependencies = [ "thiserror", "tokio", "toml 0.7.2", + "tracing", "tracing-subscriber", "typetag", "uuid", diff --git a/crates/voicevox_core_c_api/Cargo.toml b/crates/voicevox_core_c_api/Cargo.toml index 9264fc183..58db5c0ec 100644 --- a/crates/voicevox_core_c_api/Cargo.toml +++ b/crates/voicevox_core_c_api/Cargo.toml @@ -18,11 +18,13 @@ directml = ["voicevox_core/directml"] [dependencies] cstr = "0.2.11" derive-getters.workspace = true +itertools.workspace = true libc = "0.2.134" once_cell.workspace = true serde_json.workspace = true thiserror.workspace = true tokio.workspace = true +tracing.workspace = true tracing-subscriber.workspace = true uuid.workspace = true voicevox_core.workspace = true diff --git a/crates/voicevox_core_c_api/src/helpers.rs b/crates/voicevox_core_c_api/src/helpers.rs index 0b889e60c..7cc8c1df3 100644 --- a/crates/voicevox_core_c_api/src/helpers.rs +++ b/crates/voicevox_core_c_api/src/helpers.rs @@ -1,7 +1,8 @@ -use std::fmt::Debug; +use std::{error::Error as _, fmt::Debug, iter}; use voicevox_core::UserDictWord; use thiserror::Error; +use tracing::error; use super::*; use voicevox_core::AccentPhraseModel; @@ -13,8 +14,11 @@ pub(crate) fn into_result_code_with_error(result: CApiResult<()>) -> VoicevoxRes return into_result_code(result); fn display_error(err: &CApiError) { - eprintln!("Error(Display): {err}"); - eprintln!("Error(Debug): {err:#?}"); + itertools::chain( + [err.to_string()], + iter::successors(err.source(), |&e| e.source()).map(|e| format!("Caused by: {e}")), + ) + .for_each(|msg| error!("{msg}")); } fn into_result_code(result: CApiResult<()>) -> VoicevoxResultCode {