Skip to content

Commit 4a67005

Browse files
committed
Don't stop adding sections on the first error.
The "error" might be returned when a section is attempted to be added and the user specified other sections instead.
1 parent 7d8b072 commit 4a67005

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

examples/info_handler_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn add_info(ctx: &InfoContext, _for_crash_report: bool) -> RedisResult<()> {
1111
.field("key", "value")?
1212
.build_dictionary()?
1313
.build_section()?
14-
.build_info();
14+
.build_info()?;
1515

1616
Ok(())
1717
}

examples/info_handler_multiple_sections.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::HashMap;
2-
31
use redis_module::InfoContext;
42
use redis_module::{redis_module, RedisResult};
53
use redis_module_macros::{info_command_handler, InfoSection};
@@ -19,7 +17,7 @@ fn add_info(ctx: &InfoContext, _for_crash_report: bool) -> RedisResult<()> {
1917
let data = InfoSection1 {
2018
field_1: "value1".to_owned(),
2119
};
22-
let _ = ctx.build_one_section(data);
20+
let _ = ctx.build_one_section(data)?;
2321

2422
let data = InfoSection2 {
2523
field_2: "value2".to_owned(),

examples/test_helper.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::HashMap;
2-
31
use redis_module::{redis_module, Context, RedisError, RedisResult, RedisString};
42
use redis_module::{InfoContext, Status};
53

@@ -32,12 +30,10 @@ fn test_helper_err(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
3230
Ok(().into())
3331
}
3432

35-
fn add_info(ctx: &InfoContext, _for_crash_report: bool) -> RedisResult<()> {
33+
fn add_info(ctx: &InfoContext, _for_crash_report: bool) {
3634
if ctx.add_info_section(Some("test_helper")) == Status::Ok {
3735
ctx.add_info_field_str("field", "value");
3836
}
39-
40-
Ok(())
4137
}
4238

4339
//////////////////////////////////////////////////////

src/context/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,12 +1158,12 @@ impl<'a> InfoContextBuilder<'a> {
11581158
self.sections
11591159
.iter()
11601160
.try_for_each(|(section_name, section_fields)| -> RedisResult<()> {
1161-
Into::<RedisResult<()>>::into(add_info_section(
1162-
self.context.ctx,
1163-
Some(section_name),
1164-
))?;
1165-
1166-
self.add_top_level_fields(section_fields)
1161+
if add_info_section(self.context.ctx, Some(section_name)) == Status::Ok {
1162+
self.add_top_level_fields(section_fields)
1163+
} else {
1164+
// This section wasn't requested.
1165+
Ok(())
1166+
}
11671167
})
11681168
}
11691169

src/macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,14 @@ macro_rules! redis_module {
156156
#[global_allocator]
157157
static REDIS_MODULE_ALLOCATOR: $allocator_type = $allocator_init;
158158

159-
// The info handler, if specified.
159+
// The old-style info command handler, if specified.
160160
$(
161161
#[redis_module_macros::info_command_handler]
162162
#[inline]
163163
fn module_info(ctx: &InfoContext, for_crash_report: bool) -> RedisResult<()> {
164-
$info_func(ctx, for_crash_report)
164+
$info_func(ctx, for_crash_report);
165+
166+
Ok(())
165167
}
166168
)?
167169

0 commit comments

Comments
 (0)