Skip to content

Commit

Permalink
Map unreachable types to Result::Err rather than USP Error
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Egger <[email protected]>
  • Loading branch information
therealprof committed Oct 9, 2024
1 parent 4ce8f17 commit ff532c4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/usp_builder/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::usp::Body;
use crate::usp::Header;
use crate::usp::Msg;

use anyhow::anyhow;
use anyhow::{Context, Result};

#[derive(Clone)]
Expand Down Expand Up @@ -35,7 +36,7 @@ impl MsgBuilder {
}

pub fn build(self) -> Result<Msg> {
use crate::usp::mod_Body::OneOfmsg_body::{error, request, response};
use crate::usp::mod_Body::OneOfmsg_body::{request, response};
use crate::usp::mod_Header::MsgType::{
ADD, ADD_RESP, DELETE, DELETE_RESP, DEREGISTER, DEREGISTER_RESP, ERROR, GET,
GET_INSTANCES, GET_INSTANCES_RESP, GET_RESP, GET_SUPPORTED_DM, GET_SUPPORTED_DM_RESP,
Expand Down Expand Up @@ -72,7 +73,7 @@ impl MsgBuilder {
get_supported_protocol(_) => GET_SUPPORTED_PROTO,
register(_) => REGISTER,
deregister(_) => DEREGISTER,
OneOfreq_type::None => ERROR,
OneOfreq_type::None => anyhow::bail!("Request type can't be None"),
},
response(ref resp) => match &resp.resp_type {
get_resp(_) => GET_RESP,
Expand All @@ -86,9 +87,10 @@ impl MsgBuilder {
get_supported_protocol_resp(_) => GET_SUPPORTED_PROTO_RESP,
register_resp(_) => REGISTER_RESP,
deregister_resp(_) => DEREGISTER_RESP,
OneOfresp_type::None => ERROR,
OneOfresp_type::None => Err(anyhow!("Response type can't be None"))?,
},
error(_) | OneOfmsg_body::None => ERROR,
OneOfmsg_body::error(_) => ERROR,
OneOfmsg_body::None => Err(anyhow!("Body type can't be None"))?,
};

Ok(Msg {
Expand Down

0 comments on commit ff532c4

Please sign in to comment.