chiark / gitweb /
daemon: Fix many errors (OER rather than OE)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 30 Jan 2021 23:46:14 +0000 (23:46 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 31 Jan 2021 00:40:56 +0000 (00:40 +0000)
Firstly, all these functions shuuld throw OER which is the thing which
implements the Rocket Responder trait, so that the error actually goes
back to the client.

Secondly, they all need ?.  Without that, these functions all always
succeed and always return Result::Ok(some Result<, OE[R]>).
Surprisingly this is accepted, because Result<> impl Responder
and apparently Result<Result<..>> does too!

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
daemon/main.rs

index 97c3779ba96911e2bdc14889818094b5024bfc05..eea0cdce8a79772d957ab881fa30f3b42414392c 100644 (file)
@@ -177,10 +177,10 @@ fn api_piece_op<O: ApiPieceOp>(form : Json<ApiPiece<O>>)
 struct ApiPieceGrab {
 }
 #[post("/_/api/grab", format="json", data="<form>")]
-#[throws(OE)]
+#[throws(OER)]
 fn api_grab(form : Json<ApiPiece<ApiPieceGrab>>)
             -> impl response::Responder<'static> {
-  api_piece_op(form)
+  api_piece_op(form)?
 }
 impl ApiPieceOp for ApiPieceGrab {
   #[throws(ApiPieceOpError)]
@@ -204,10 +204,10 @@ impl ApiPieceOp for ApiPieceGrab {
 struct ApiPieceWrest {
 }
 #[post("/_/api/wrest", format="json", data="<form>")]
-#[throws(OE)]
+#[throws(OER)]
 fn api_wrest(form : Json<ApiPiece<ApiPieceWrest>>)
             -> impl response::Responder<'static> {
-  api_piece_op(form)
+  api_piece_op(form)?
 }
 impl ApiPieceOp for ApiPieceWrest {
   #[throws(OnlineError)]
@@ -243,10 +243,10 @@ impl ApiPieceOp for ApiPieceWrest {
 struct ApiPieceUngrab {
 }
 #[post("/_/api/ungrab", format="json", data="<form>")]
-#[throws(OE)]
+#[throws(OER)]
 fn api_ungrab(form : Json<ApiPiece<ApiPieceUngrab>>)
               -> impl response::Responder<'static> {
-  api_piece_op(form)
+  api_piece_op(form)?
 }
 impl ApiPieceOp for ApiPieceUngrab {
   #[throws(ApiPieceOpError)]
@@ -271,10 +271,10 @@ struct ApiPieceSetZ {
   z : ZCoord,
 }
 #[post("/_/api/setz", format="json", data="<form>")]
-#[throws(OE)]
+#[throws(OER)]
 fn api_raise(form : Json<ApiPiece<ApiPieceSetZ>>)
             -> impl response::Responder<'static> {
-  api_piece_op(form)
+  api_piece_op(form)?
 }
 impl ApiPieceOp for ApiPieceSetZ {
   #[throws(ApiPieceOpError)]
@@ -291,9 +291,9 @@ impl ApiPieceOp for ApiPieceSetZ {
 #[derive(Debug,Serialize,Deserialize)]
 struct ApiPieceMove (Pos);
 #[post("/_/api/m", format="json", data="<form>")]
-#[throws(OE)]
+#[throws(OER)]
 fn api_move(form : Json<ApiPiece<ApiPieceMove>>) -> impl response::Responder<'static> {
-  api_piece_op(form)
+  api_piece_op(form)?
 }
 impl ApiPieceOp for ApiPieceMove {
   #[throws(ApiPieceOpError)]
@@ -318,9 +318,9 @@ impl ApiPieceOp for ApiPieceMove {
 #[derive(Debug,Serialize,Deserialize)]
 struct ApiPieceRotate(CompassAngle);
 #[post("/_/api/rotate", format="json", data="<form>")]
-#[throws(OE)]
+#[throws(OER)]
 fn api_rotate(form : Json<ApiPiece<ApiPieceRotate>>) -> impl response::Responder<'static> {
-  api_piece_op(form)
+  api_piece_op(form)?
 }
 impl ApiPieceOp for ApiPieceRotate {
   #[throws(ApiPieceOpError)]
@@ -339,9 +339,9 @@ impl ApiPieceOp for ApiPieceRotate {
 #[derive(Debug,Serialize,Deserialize)]
 struct ApiPiecePin (bool);
 #[post("/_/api/pin", format="json", data="<form>")]
-#[throws(OE)]
+#[throws(OER)]
 fn api_pin(form : Json<ApiPiece<ApiPiecePin>>) -> impl response::Responder<'static> {
-  api_piece_op(form)
+  api_piece_op(form)?
 }
 impl ApiPieceOp for ApiPiecePin {
   #[throws(ApiPieceOpError)]
@@ -365,9 +365,9 @@ const DEFKEY_FLIP : UoKey = 'f';
 #[derive(Debug,Serialize,Deserialize)]
 struct ApiPieceUo { opname: String, wrc: WhatResponseToClientOp }
 #[post("/_/api/k", format="json", data="<form>")]
-#[throws(OE)]
+#[throws(OER)]
 fn api_uo(form : Json<ApiPiece<ApiPieceUo>>) -> impl response::Responder<'static> {
-  api_piece_op(form)
+  api_piece_op(form)?
 }
 impl ApiPieceOp for ApiPieceUo {
   #[throws(ApiPieceOpError)]
index 4c34e74028bd321c468abf61ec931a89f1570326..da569460c6811a22f67cb56a895b18c38edf6223 100644 (file)
@@ -165,7 +165,7 @@ impl<'r, T> FromParam<'r> for Parse<T>
 }
 
 #[get("/_/updates?<ctoken>&<gen>")]
-#[throws(OE)]
+#[throws(OER)]
 fn updates<'r>(ctoken : InstanceAccess<ClientId>, gen: u64,
                cors: rocket_cors::Guard<'r>)
                -> impl response::Responder<'r> {