Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtimes/core+js: add details to errors #1491

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions runtimes/core/src/api/auth/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl AuthHandler for LocalAuthHandler {
"auth handler did not return a userID field".to_string(),
),
stack: None,
details: None,
}),
}
}
Expand All @@ -127,6 +128,7 @@ impl AuthHandler for LocalAuthHandler {
message: "unauthenticated".to_string(),
internal_message: Some("auth handler returned null".to_string()),
stack: None,
details: None,
}),
Err(e) => Err(e),
};
Expand Down
6 changes: 6 additions & 0 deletions runtimes/core/src/api/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl ServiceRegistry {
endpoint_name.service()
)),
stack: None,
details: None,
})?;

let Some(endpoint) = self.endpoints.get(endpoint_name) else {
Expand All @@ -165,6 +166,7 @@ impl ServiceRegistry {
endpoint_name
)),
stack: None,
details: None,
});
};

Expand All @@ -180,6 +182,7 @@ impl ServiceRegistry {
endpoint_name
)),
stack: None,
details: None,
})?;

let mut req = self
Expand Down Expand Up @@ -207,6 +210,7 @@ impl ServiceRegistry {
message: "internal error".into(),
internal_message: Some("cannot make api calls to raw endpoints".to_string()),
stack: None,
details: None,
});
}
}
Expand Down Expand Up @@ -239,6 +243,7 @@ impl ServiceRegistry {
endpoint.name.service()
)),
stack: None,
details: None,
})?;

let caller = match source {
Expand Down Expand Up @@ -328,6 +333,7 @@ where
message: body,
internal_message: None,
stack: None,
details: None,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions runtimes/core/src/api/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ impl EndpointHandler {
message: "endpoint not found".into(),
internal_message: Some("the endpoint was found, but is not exposed".into()),
stack: None,
details: None,
}
.into_response();
} else if self.endpoint.requires_auth && !request.has_authenticated_user() {
Expand All @@ -483,6 +484,7 @@ impl EndpointHandler {
message: "endpoint requires auth but none provided".into(),
internal_message: None,
stack: None,
details: None,
}
.into_response();
}
Expand Down
6 changes: 6 additions & 0 deletions runtimes/core/src/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Error {
pub code: ErrCode,
pub message: String,
pub internal_message: Option<String>,
pub details: Option<serde_json::Map<String, serde_json::Value>>,

#[serde(skip_serializing)]
pub stack: Option<StackTrace>,
Expand All @@ -27,6 +28,7 @@ impl Error {
message: ErrCode::Internal.default_public_message().into(),
internal_message: Some(format!("{:#?}", cause.into())),
stack: None,
details: None,
}
}

Expand All @@ -40,6 +42,7 @@ impl Error {
message: public_msg.into(),
internal_message: Some(format!("{:#?}", cause.into())),
stack: None,
details: None,
}
}

Expand All @@ -52,6 +55,7 @@ impl Error {
message: public_msg.into(),
internal_message: None,
stack: None,
details: None,
}
}

Expand All @@ -61,6 +65,7 @@ impl Error {
message: ErrCode::Unauthenticated.default_public_message().into(),
internal_message: None,
stack: None,
details: None,
}
}
}
Expand All @@ -72,6 +77,7 @@ impl From<WebSocketUpgradeRejection> for Error {
message: value.body_text(),
internal_message: Some(value.body_text()),
stack: None,
details: None,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions runtimes/core/src/api/gateway/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ impl Router {
message: "no route for method".to_string(),
internal_message: Some(format!("no route for method {:?}: {}", method, path)),
stack: None,
details: None,
}
} else {
api::Error {
code: api::ErrCode::NotFound,
message: "endpoint not found".to_string(),
internal_message: Some(format!("no such endpoint exists: {}", path)),
stack: None,
details: None,
}
})
}
Expand Down
14 changes: 14 additions & 0 deletions runtimes/core/src/api/jsonschema/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ macro_rules! header_to_str {
message: "invalid header value".to_string(),
internal_message: Some(format!("invalid header value: {}", err)),
stack: None,
details: None,
})
};
}
Expand All @@ -43,6 +44,7 @@ where
message: format!("missing required header: {}", header_name),
internal_message: None,
stack: None,
details: None,
});
}
};
Expand Down Expand Up @@ -130,6 +132,7 @@ fn parse_header_value(header: &str, reg: &Registry, schema: &Value) -> APIResult
message: "invalid header value".to_string(),
internal_message: Some(format!("invalid float value: {}", header)),
stack: None,
details: None,
})
}
}
Expand All @@ -139,6 +142,7 @@ fn parse_header_value(header: &str, reg: &Registry, schema: &Value) -> APIResult
message: "invalid header value".to_string(),
internal_message: Some(format!("expected {}, got {}", want.expecting(), header)),
stack: None,
details: None,
}),
},

Expand All @@ -162,6 +166,7 @@ fn parse_header_value(header: &str, reg: &Registry, schema: &Value) -> APIResult
message: "invalid header value".to_string(),
internal_message: Some(format!("no union value matched: {}", header)),
stack: None,
details: None,
})
}
}
Expand Down Expand Up @@ -224,6 +229,7 @@ fn parse_json_value(
message: "invalid value".to_string(),
internal_message: Some(format!("expected {}, got {:#?}", lit.expecting(), got)),
stack: None,
details: None,
})
};

Expand Down Expand Up @@ -326,6 +332,7 @@ fn parse_json_value(
message: "invalid value".to_string(),
internal_message: Some(format!("no union type matched: {}", describe_json(&this),)),
stack: None,
details: None,
})
}
}
Expand All @@ -341,6 +348,7 @@ fn unexpected_json(reg: &Registry, schema: &Value, value: &JSON) -> APIResult<JS
describe_json(value),
)),
stack: None,
details: None,
})
}

Expand All @@ -353,6 +361,7 @@ fn unsupported<T>(reg: &Registry, schema: &Value) -> APIResult<T> {
schema.expecting(reg),
)),
stack: None,
details: None,
})
}

Expand Down Expand Up @@ -392,6 +401,7 @@ fn parse_basic_json(
message: format!("invalid boolean value: {}", str),
internal_message: None,
stack: None,
details: None,
}),
},
Basic::Number => serde_json::Number::from_str(str)
Expand All @@ -401,6 +411,7 @@ fn parse_basic_json(
message: format!("invalid number value: {}", str),
internal_message: None,
stack: None,
details: None,
}),
Basic::Null if str == "null" => Ok(JSON::Null),

Expand All @@ -425,6 +436,7 @@ fn parse_basic_str(basic: &Basic, str: &str) -> APIResult<serde_json::Value> {
message: format!("invalid boolean value: {}", str),
internal_message: None,
stack: None,
details: None,
}),
},

Expand All @@ -435,13 +447,15 @@ fn parse_basic_str(basic: &Basic, str: &str) -> APIResult<serde_json::Value> {
message: format!("invalid number value: {}", str),
internal_message: None,
stack: None,
details: None,
}),

_ => Err(api::Error {
code: api::ErrCode::InvalidArgument,
message: "invalid value".to_string(),
internal_message: Some(format!("expected {}, got {:#?}", basic.expecting(), str)),
stack: None,
details: None,
}),
}
}
1 change: 1 addition & 0 deletions runtimes/core/src/api/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ impl Manager {
message: "endpoint not found".to_string(),
internal_message: Some(format!("no such endpoint exists: {}", req.uri().path())),
stack: None,
details: None,
}
.into_response()
}
Expand Down
2 changes: 2 additions & 0 deletions runtimes/core/src/api/schema/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl ToOutgoingRequest for Body {
message: "missing body payload".to_string(),
internal_message: None,
stack: None,
details: None,
});
};

Expand All @@ -76,6 +77,7 @@ impl Body {
message: "missing body payload".to_string(),
internal_message: None,
stack: None,
details: None,
});
};

Expand Down
10 changes: 10 additions & 0 deletions runtimes/core/src/api/schema/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ impl ToOutgoingRequest for Header {
message: "missing query parameters".to_string(),
internal_message: Some("missing query parameters".to_string()),
stack: None,
details: None,
});
};

Expand Down Expand Up @@ -219,6 +220,7 @@ impl ToResponse for Header {
message: "missing query parameters".to_string(),
internal_message: Some("missing query parameters".to_string()),
stack: None,
details: None,
});
};

Expand Down Expand Up @@ -267,6 +269,7 @@ fn to_reqwest_header_value(value: &serde_json::Value) -> APIResult<ReqwestHeader
message: "unable to convert string to header value".to_string(),
internal_message: Some(format!("unable to convert string to header value: {}", e)),
stack: None,
details: None,
})?,

Number(num) => {
Expand All @@ -276,6 +279,7 @@ fn to_reqwest_header_value(value: &serde_json::Value) -> APIResult<ReqwestHeader
message: "unable to convert number to header value".to_string(),
internal_message: Some(format!("unable to convert number to header value: {}", e)),
stack: None,
details: None,
})?
}

Expand All @@ -290,6 +294,7 @@ fn to_reqwest_header_value(value: &serde_json::Value) -> APIResult<ReqwestHeader
message: "nested array type unsupported as header value".into(),
internal_message: None,
stack: None,
details: None,
})
}
}
Expand All @@ -303,6 +308,7 @@ fn to_reqwest_header_value(value: &serde_json::Value) -> APIResult<ReqwestHeader
message: "map type unsupported as header value".into(),
internal_message: None,
stack: None,
details: None,
})
}
}))
Expand All @@ -326,6 +332,7 @@ fn to_axum_header_value(value: &serde_json::Value) -> APIResult<AxumHeaders> {
message: "unable to convert string to header value".to_string(),
internal_message: Some(format!("unable to convert string to header value: {}", e)),
stack: None,
details: None,
})?,

Number(num) => {
Expand All @@ -335,6 +342,7 @@ fn to_axum_header_value(value: &serde_json::Value) -> APIResult<AxumHeaders> {
message: "unable to convert number to header value".to_string(),
internal_message: Some(format!("unable to convert number to header value: {}", e)),
stack: None,
details: None,
})?
}

Expand All @@ -349,6 +357,7 @@ fn to_axum_header_value(value: &serde_json::Value) -> APIResult<AxumHeaders> {
message: "nested array type unsupported as header value".into(),
internal_message: None,
stack: None,
details: None,
})
}
}
Expand All @@ -362,6 +371,7 @@ fn to_axum_header_value(value: &serde_json::Value) -> APIResult<AxumHeaders> {
message: "map type unsupported as header value".into(),
internal_message: None,
stack: None,
details: None,
})
}
}))
Expand Down
Loading
Loading