Skip to content

Commit e60a183

Browse files
clippy suggestions
1 parent 0d0dae0 commit e60a183

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

src/catalog/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*/
1818

19-
use std::{io::ErrorKind, sync::Arc};
19+
use std::sync::Arc;
2020

2121
use chrono::{DateTime, Local, NaiveTime, Utc};
2222
use column::Column;
@@ -259,10 +259,7 @@ async fn create_manifest(
259259
.date_naive()
260260
.and_time(
261261
NaiveTime::from_num_seconds_from_midnight_opt(23 * 3600 + 59 * 60 + 59, 999_999_999)
262-
.ok_or(IOError::new(
263-
ErrorKind::Other,
264-
"Failed to create upper bound for manifest",
265-
))?,
262+
.ok_or(IOError::other("Failed to create upper bound for manifest"))?,
266263
)
267264
.and_utc();
268265

src/handlers/airplane.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ impl FlightService for AirServiceImpl {
126126
}
127127

128128
async fn do_get(&self, req: Request<Ticket>) -> Result<Response<Self::DoGetStream>, Status> {
129-
let key = extract_session_key(req.metadata())?;
129+
let key = extract_session_key(req.metadata())
130+
.map_err(|e| Status::unauthenticated(e.to_string()))?;
130131

131-
let ticket = get_query_from_ticket(&req)?;
132+
let ticket =
133+
get_query_from_ticket(&req).map_err(|e| Status::invalid_argument(e.to_string()))?;
132134

133135
info!("query requested to airplane: {:?}", ticket);
134136

@@ -246,7 +248,7 @@ impl FlightService for AirServiceImpl {
246248
.observe(time);
247249

248250
// Airplane takes off 🛫
249-
out
251+
out.map_err(|e| *e)
250252
}
251253

252254
async fn do_put(

src/handlers/livetail.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ impl FlightService for FlightServiceImpl {
9898
}
9999

100100
async fn do_get(&self, req: Request<Ticket>) -> Result<Response<Self::DoGetStream>, Status> {
101-
let key = extract_session_key(req.metadata())?;
101+
let key = extract_session_key(req.metadata()).map_err(|e| *e)?;
102102
let ticket: serde_json::Value = serde_json::from_slice(&req.into_inner().ticket)
103103
.map_err(|err| Status::internal(err.to_string()))?;
104-
let stream = extract_stream(&ticket)?;
104+
let stream = extract_stream(&ticket).map_err(|e| *e)?;
105105
info!("livetail requested for stream {}", stream);
106106
match Users.authorize(key, rbac::role::Action::Query, Some(stream), None) {
107107
rbac::Response::Authorized => (),
@@ -232,16 +232,16 @@ pub fn server() -> impl Future<Output = Result<(), Box<dyn std::error::Error + S
232232
}
233233
}
234234

235-
pub fn extract_stream(body: &serde_json::Value) -> Result<&str, Status> {
235+
pub fn extract_stream(body: &serde_json::Value) -> Result<&str, Box<Status>> {
236236
body.as_object()
237-
.ok_or(Status::invalid_argument("expected object in request body"))?
237+
.ok_or_else(|| Box::new(Status::invalid_argument("expected object in request body")))?
238238
.get("stream")
239-
.ok_or(Status::invalid_argument("stream key value is not provided"))?
239+
.ok_or_else(|| Box::new(Status::invalid_argument("stream key value is not provided")))?
240240
.as_str()
241-
.ok_or(Status::invalid_argument("stream key value is invalid"))
241+
.ok_or_else(|| Box::new(Status::invalid_argument("stream key value is invalid")))
242242
}
243243

244-
pub fn extract_session_key(headers: &MetadataMap) -> Result<SessionKey, Status> {
244+
pub fn extract_session_key(headers: &MetadataMap) -> Result<SessionKey, Box<Status>> {
245245
// Extract username and password from the request using basic auth extractor.
246246
let basic = extract_basic_auth(headers).map(|creds| SessionKey::BasicAuth {
247247
username: creds.user_id,
@@ -261,7 +261,9 @@ pub fn extract_session_key(headers: &MetadataMap) -> Result<SessionKey, Status>
261261
return Ok(SessionKey::SessionId(session));
262262
}
263263

264-
Err(Status::unauthenticated("No authentication method supplied"))
264+
Err(Box::new(Status::unauthenticated(
265+
"No authentication method supplied",
266+
)))
265267
}
266268

267269
fn extract_basic_auth(header: &MetadataMap) -> Option<Credentials> {

src/utils/arrow/flight.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ use tonic::transport::{Channel, Uri};
4141

4242
pub type DoGetStream = stream::BoxStream<'static, Result<FlightData, Status>>;
4343

44-
pub fn get_query_from_ticket(req: &Request<Ticket>) -> Result<QueryJson, Status> {
44+
pub fn get_query_from_ticket(req: &Request<Ticket>) -> Result<QueryJson, Box<Status>> {
4545
serde_json::from_slice::<QueryJson>(&req.get_ref().ticket)
46-
.map_err(|err| Status::internal(err.to_string()))
46+
.map_err(|err| Box::new(Status::internal(err.to_string())))
4747
}
4848

4949
pub async fn run_do_get_rpc(
@@ -141,7 +141,7 @@ fn lit_timestamp_milli(time: i64) -> Expr {
141141
Expr::Literal(ScalarValue::TimestampMillisecond(Some(time), None))
142142
}
143143

144-
pub fn into_flight_data(records: Vec<RecordBatch>) -> Result<Response<DoGetStream>, Status> {
144+
pub fn into_flight_data(records: Vec<RecordBatch>) -> Result<Response<DoGetStream>, Box<Status>> {
145145
let input_stream = futures::stream::iter(records.into_iter().map(Ok));
146146
let write_options = IpcWriteOptions::default()
147147
.try_with_compression(Some(arrow_ipc::CompressionType(1)))

0 commit comments

Comments
 (0)