Skip to content

Commit 47f2d44

Browse files
'declare queue': handle unknown --type values better
This allows unknown types to be passed on as they are via QueueType::Unsupported(String). Alternatively we now have the infrastructure to immediately return an error instead.
1 parent e81ab61 commit 47f2d44

File tree

6 files changed

+44
-21
lines changed

6 files changed

+44
-21
lines changed

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ fn declare_subcommands() -> [Command; 12] {
533533
.long("type")
534534
.help("queue type")
535535
.value_parser(value_parser!(QueueType))
536-
.required(false),
536+
.required(false)
537+
.default_value("classic"),
537538
)
538539
.arg(
539540
Arg::new("durable")

src/commands.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use rabbitmq_http_client::requests::{
2828
use std::fs;
2929
use std::process;
3030

31-
use crate::constants::DEFAULT_QUEUE_TYPE;
3231
use rabbitmq_http_client::commons::BindingDestinationType;
3332
use rabbitmq_http_client::commons::QueueType;
3433
use rabbitmq_http_client::{password_hashing, requests, responses};
@@ -629,10 +628,8 @@ pub fn declare_queue(
629628
) -> ClientResult<()> {
630629
// the flag is required
631630
let name = command_args.get_one::<String>("name").unwrap();
632-
let queue_type = command_args
633-
.get_one::<QueueType>("type")
634-
.cloned()
635-
.unwrap_or(QueueType::from(DEFAULT_QUEUE_TYPE));
631+
let queue_type = command_args.get_one::<QueueType>("type").cloned().unwrap();
632+
636633
// these are optional
637634
let durable = command_args
638635
.get_one::<bool>("durable")

src/errors.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ pub enum CommandRunError {
7373
ConflictingOptions { message: String },
7474
#[error("{message}")]
7575
MissingOptions { message: String },
76+
#[error("Unsupported argument value for property (field) {property}")]
77+
UnsupportedArgumentValue { property: String },
7678
#[error("This request produces an invalid HTTP header value")]
7779
InvalidHeaderValue { error: InvalidHeaderValue },
7880
#[error("encountered an error when performing an HTTP request")]
@@ -90,6 +92,9 @@ impl From<std::io::Error> for CommandRunError {
9092
impl From<HttpClientError> for CommandRunError {
9193
fn from(value: HttpClientError) -> Self {
9294
match value {
95+
ApiClientError::UnsupportedArgumentValue { property } => {
96+
Self::UnsupportedArgumentValue { property }
97+
}
9398
ApiClientError::ClientErrorResponse { status_code, url, body, headers, .. } => {
9499
Self::ClientError { status_code, url, body, headers }
95100
},

src/output.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ impl<'a> ResultHandler<'a> {
381381
// We cannot implement From<T> for two types in other crates, so…
382382
pub(crate) fn client_error_to_exit_code(error: &HttpClientError) -> ExitCode {
383383
match error {
384+
ClientError::UnsupportedArgumentValue { .. } => ExitCode::DataErr,
384385
ClientError::ClientErrorResponse { .. } => ExitCode::DataErr,
385386
ClientError::ServerErrorResponse { .. } => ExitCode::Unavailable,
386387
ClientError::HealthCheckFailed { .. } => ExitCode::Unavailable,

src/tables.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,25 @@ pub fn schema_definition_sync_status(status: SchemaDefinitionSyncStatus) -> Tabl
252252

253253
pub fn failure_details(error: &HttpClientError) -> Table {
254254
match error {
255+
HttpClientError::UnsupportedArgumentValue { property } => {
256+
let message = format!(
257+
"Unsupported argument value for property (field) {}",
258+
property
259+
);
260+
let data = vec![
261+
RowOfTwo {
262+
key: "result",
263+
value: "request was not executed",
264+
},
265+
RowOfTwo {
266+
key: "message",
267+
value: &message,
268+
},
269+
];
270+
271+
let tb = Table::builder(data);
272+
tb.build()
273+
}
255274
HttpClientError::ClientErrorResponse {
256275
status_code,
257276
url,

0 commit comments

Comments
 (0)