Skip to content

Commit

Permalink
refacto(client): call helper function to generate the error message
Browse files Browse the repository at this point in the history
  • Loading branch information
creberust committed Feb 22, 2024
1 parent 3289858 commit 0e33be3
Showing 1 changed file with 51 additions and 41 deletions.
92 changes: 51 additions & 41 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{borrow::Cow, fmt::Debug, io};

use async_trait::async_trait;

use crate::{frame::*, slave::*, Result};
use crate::{error::unexpected_rsp_code_panic_msg, frame::*, slave::*, Result};

#[cfg(feature = "rtu")]
pub mod rtu;
Expand Down Expand Up @@ -140,10 +140,11 @@ impl Reader for Context {
// NOTE: A call to `Client::call` implementation *MUST* always return the `Response` variant matching the `Request` one.
// TIPS: This can be ensured via a call to `verify_response_header`( in 'src/service/mod.rs') before returning from `Client::call`.
unreachable!(
"unexpected response code: {} (request code: {})\n\
note: Please fill an issue at `https://github.com/slowtec/tokio-modbus/issues` with a minimal example reproducing this bug.",
others.function_code(),
FunctionCode::ReadCoils
"{}",
unexpected_rsp_code_panic_msg(
FunctionCode::ReadCoils,
others.function_code()
),
)
}
})
Expand All @@ -169,10 +170,11 @@ impl Reader for Context {
// NOTE: A call to `Client::call` implementation *MUST* always return the `Response` variant matching the `Request` one.
// TIPS: This can be ensured via a call to `verify_response_header`( in 'src/service/mod.rs') before returning from `Client::call`.
unreachable!(
"unexpected response code: {} (request code: {})\n\
note: Please fill an issue at `https://github.com/slowtec/tokio-modbus/issues` with a minimal example reproducing this bug.",
others.function_code(),
FunctionCode::ReadDiscreteInputs
"{}",
unexpected_rsp_code_panic_msg(
FunctionCode::ReadDiscreteInputs,
others.function_code()
),
)
}
})
Expand All @@ -197,10 +199,11 @@ impl Reader for Context {
// NOTE: A call to `Client::call` implementation *MUST* always return the `Response` variant matching the `Request` one.
// TIPS: This can be ensured via a call to `verify_response_header`( in 'src/service/mod.rs') before returning from `Client::call`.
unreachable!(
"unexpected response code: {} (request code: {})\n\
note: Please fill an issue at `https://github.com/slowtec/tokio-modbus/issues` with a minimal example reproducing this bug.",
others.function_code(),
FunctionCode::ReadInputRegisters
"{}",
unexpected_rsp_code_panic_msg(
FunctionCode::ReadInputRegisters,
others.function_code()
),
)
}
})
Expand All @@ -225,10 +228,11 @@ impl Reader for Context {
// NOTE: A call to `Client::call` implementation *MUST* always return the `Response` variant matching the `Request` one.
// TIPS: This can be ensured via a call to `verify_response_header`( in 'src/service/mod.rs') before returning from `Client::call`.
unreachable!(
"unexpected response code: {} (request code: {})\n\
note: Please fill an issue at `https://github.com/slowtec/tokio-modbus/issues` with a minimal example reproducing this bug.",
others.function_code(),
FunctionCode::ReadHoldingRegisters
"{}",
unexpected_rsp_code_panic_msg(
FunctionCode::ReadHoldingRegisters,
others.function_code()
),
)
}
})
Expand Down Expand Up @@ -260,10 +264,11 @@ impl Reader for Context {
// NOTE: A call to `Client::call` implementation *MUST* always return the `Response` variant matching the `Request` one.
// TIPS: This can be ensured via a call to `verify_response_header`( in 'src/service/mod.rs') before returning from `Client::call`.
unreachable!(
"unexpected response code: {} (request code: {})\n\
note: Please fill an issue at `https://github.com/slowtec/tokio-modbus/issues` with a minimal example reproducing this bug.",
others.function_code(),
FunctionCode::ReadWriteMultipleRegisters
"{}",
unexpected_rsp_code_panic_msg(
FunctionCode::ReadWriteMultipleRegisters,
others.function_code()
),
)
}
})
Expand All @@ -287,10 +292,11 @@ impl Writer for Context {
// NOTE: A call to `Client::call` implementation *MUST* always return the `Response` variant matching the `Request` one.
// TIPS: This can be ensured via a call to `verify_response_header`( in 'src/service/mod.rs') before returning from `Client::call`.
unreachable!(
"unexpected response code: {} (request code: {})\n\
note: Please fill an issue at `https://github.com/slowtec/tokio-modbus/issues` with a minimal example reproducing this bug.",
others.function_code(),
FunctionCode::WriteSingleCoil
"{}",
unexpected_rsp_code_panic_msg(
FunctionCode::WriteSingleCoil,
others.function_code()
),
)
}
})
Expand All @@ -313,10 +319,11 @@ impl Writer for Context {
// NOTE: A call to `Client::call` implementation *MUST* always return the `Response` variant matching the `Request` one.
// TIPS: This can be ensured via a call to `verify_response_header`( in 'src/service/mod.rs') before returning from `Client::call`.
unreachable!(
"unexpected response code: {} (request code: {})\n\
note: Please fill an issue at `https://github.com/slowtec/tokio-modbus/issues` with a minimal example reproducing this bug.",
others.function_code(),
FunctionCode::WriteMultipleCoils
"{}",
unexpected_rsp_code_panic_msg(
FunctionCode::WriteMultipleCoils,
others.function_code()
),
)
}
})
Expand All @@ -337,10 +344,11 @@ impl Writer for Context {
// NOTE: A call to `Client::call` implementation *MUST* always return the `Response` variant matching the `Request` one.
// TIPS: This can be ensured via a call to `verify_response_header`( in 'src/service/mod.rs') before returning from `Client::call`.
unreachable!(
"unexpected response code: {} (request code: {})\n\
note: Please fill an issue at `https://github.com/slowtec/tokio-modbus/issues` with a minimal example reproducing this bug.",
others.function_code(),
FunctionCode::WriteSingleRegister
"{}",
unexpected_rsp_code_panic_msg(
FunctionCode::WriteSingleRegister,
others.function_code()
),
)
}
})
Expand All @@ -367,10 +375,11 @@ impl Writer for Context {
// NOTE: A call to `Client::call` implementation *MUST* always return the `Response` variant matching the `Request` one.
// TIPS: This can be ensured via a call to `verify_response_header`( in 'src/service/mod.rs') before returning from `Client::call`.
unreachable!(
"unexpected response code: {} (request code: {})\n\
note: Please fill an issue at `https://github.com/slowtec/tokio-modbus/issues` with a minimal example reproducing this bug.",
others.function_code(),
FunctionCode::WriteMultipleRegisters
"{}",
unexpected_rsp_code_panic_msg(
FunctionCode::WriteMultipleRegisters,
others.function_code()
),
)
}
})
Expand All @@ -397,10 +406,11 @@ impl Writer for Context {
// NOTE: A call to `Client::call` implementation *MUST* always return the `Response` variant matching the `Request` one.
// TIPS: This can be ensured via a call to `verify_response_header`( in 'src/service/mod.rs') before returning from `Client::call`.
unreachable!(
"unexpected response code: {} (request code: {})\n\
note: Please fill an issue at `https://github.com/slowtec/tokio-modbus/issues` with a minimal example reproducing this bug.",
others.function_code(),
FunctionCode::MaskWriteRegister
"{}",
unexpected_rsp_code_panic_msg(
FunctionCode::MaskWriteRegister,
others.function_code()
),
)
}
})
Expand Down

0 comments on commit 0e33be3

Please sign in to comment.