Keep -32602 and existing validation order; tell callers to send the object itself. Cover host routing, stdout fast paths, SDK calls and generated dispatch. Card: SAU-317
This commit is contained in:
+1
-1
@@ -37,7 +37,7 @@ impl IntoFuture for Call {
|
||||
fn into_future(self) -> Self::IntoFuture {
|
||||
Box::pin(async move {
|
||||
if !self.params.is_object() {
|
||||
return Err(Error::new(-32602, "params must be an object"));
|
||||
return Err(Error::params_not_object(&self.params));
|
||||
}
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let id = STATE.with(|s| {
|
||||
|
||||
@@ -15,6 +15,25 @@ pub struct Error {
|
||||
pub data: Option<Value>,
|
||||
}
|
||||
impl Error {
|
||||
/// Build the object-params diagnostic used by calls and generated dispatch.
|
||||
#[doc(hidden)]
|
||||
pub fn params_not_object(params: &Value) -> Self {
|
||||
let kind = match params {
|
||||
Value::String(_) => "a string",
|
||||
Value::Array(_) => "an array",
|
||||
Value::Number(_) => "a number",
|
||||
Value::Null => "null",
|
||||
Value::Bool(_) => "a boolean",
|
||||
Value::Object(_) => "an object",
|
||||
};
|
||||
Self::new(
|
||||
-32602,
|
||||
format!(
|
||||
"params must be a JSON object, got {kind}. Send the object itself, not a JSON-encoded string."
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/// Construct an error without structured details.
|
||||
pub fn new(code: i64, message: impl Into<String>) -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user