From 2ae41ff171843ec3e6d2614b809a0ce9c6e37623 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Tue, 26 Nov 2024 11:38:08 +0800 Subject: [PATCH] Remove rpc backtrace, resolve #4698 Signed-off-by: Eval EXEC --- rpc/src/error.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rpc/src/error.rs b/rpc/src/error.rs index 753f747dbe..ba702456d6 100644 --- a/rpc/src/error.rs +++ b/rpc/src/error.rs @@ -121,6 +121,14 @@ pub enum RPCError { Indexer = -1200, } +/// Removes the backtrace portion from an error string. +fn remove_backtrace(err_str: &str) -> &str { + match err_str.find("\nStack backtrace:") { + Some(idx) => &err_str[..idx], + None => err_str, + } +} + impl RPCError { /// Invalid method parameter(s). pub fn invalid_params(message: T) -> Error { @@ -158,10 +166,12 @@ impl RPCError { /// The parameter `err` is usually an std error. The Display form is used as the error message, /// and the Debug form is used as the data. pub fn custom_with_error(error_code: RPCError, err: T) -> Error { + let err_str_with_backtrace = format!("{err:?}"); + let err_str = remove_backtrace(&err_str_with_backtrace); Error { code: ErrorCode::ServerError(error_code as i64), message: format!("{error_code:?}: {err}"), - data: Some(Value::String(format!("{err:?}"))), + data: Some(Value::String(err_str.to_string())), } }