Skip to content

Commit 4a47efb

Browse files
authored
chore: switch to lowercase error msgs as per rust api guideline doc (#19)
1 parent 8f4bb15 commit 4a47efb

File tree

10 files changed

+28
-28
lines changed

10 files changed

+28
-28
lines changed

api/src/v1/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl TryFrom<RetentionPolicy> for types::config::RetentionPolicy {
5757
fn try_from(value: RetentionPolicy) -> Result<Self, Self::Error> {
5858
match value {
5959
RetentionPolicy::Age(0) => Err(types::ValidationError(
60-
"Age must be greater than 0 seconds".to_string(),
60+
"age must be greater than 0 seconds".to_string(),
6161
)),
6262
RetentionPolicy::Age(age) => Ok(Self::Age(Duration::from_secs(age))),
6363
RetentionPolicy::Infinite(_) => Ok(Self::Infinite()),

api/src/v1/stream/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl S2Format {
338338
Ok(match self {
339339
S2Format::Raw => s.into_bytes().into(),
340340
S2Format::Base64 => Base64::decode_vec(&s)
341-
.map_err(|_| types::ValidationError("Invalid Base64 encoding".to_owned()))?
341+
.map_err(|_| types::ValidationError("invalid Base64 encoding".to_owned()))?
342342
.into(),
343343
})
344344
}

api/src/v1/stream/sse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ impl FromStr for LastEventId {
5050
{
5151
let item = iter
5252
.next()
53-
.ok_or_else(|| format!("Missing {field} in Last-Event-Id"))?;
53+
.ok_or_else(|| format!("missing {field} in Last-Event-Id"))?;
5454
item.parse()
55-
.map_err(|e| format!("Invalid {field} in Last-Event-ID: {e}").into())
55+
.map_err(|e| format!("invalid {field} in Last-Event-ID: {e}").into())
5656
}
5757

5858
let seq_num = get_next(&mut iter, "seq_num")?;

common/src/record/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ impl Encodable for CommandRecord {
129129

130130
#[derive(Debug, PartialEq, thiserror::Error)]
131131
pub enum CommandPayloadError {
132-
#[error("Invalid UTF-8")]
132+
#[error("invalid UTF-8")]
133133
InvalidUtf8(Utf8Error),
134134
#[error(transparent)]
135135
FencingTokenTooLong(#[from] FencingTokenTooLongError),
136-
#[error("Earliest sequence number to trim to was {0} bytes, must be 8")]
136+
#[error("earliest sequence number to trim to was {0} bytes, must be 8")]
137137
TrimPointSize(usize),
138138
}
139139

common/src/record/envelope.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use crate::deep_size::DeepSize;
77

88
#[derive(Debug, PartialEq, thiserror::Error)]
99
pub enum HeaderValidationError {
10-
#[error("Too many")]
10+
#[error("too many")]
1111
TooMany,
12-
#[error("Too long")]
12+
#[error("too long")]
1313
TooLong,
14-
#[error("Empty name")]
14+
#[error("empty name")]
1515
NameEmpty,
1616
}
1717

common/src/record/fencing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::deep_size::DeepSize;
77
pub const MAX_FENCING_TOKEN_LENGTH: usize = 36;
88

99
#[derive(Debug, PartialEq, Eq, thiserror::Error)]
10-
#[error("Fencing token was longer than {MAX_FENCING_TOKEN_LENGTH} bytes in length: {0}")]
10+
#[error("fencing token must not exceed {MAX_FENCING_TOKEN_LENGTH} characters in length")]
1111
pub struct FencingTokenTooLongError(pub usize);
1212

1313
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]

common/src/record/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ impl DeepSize for StreamPosition {
4747

4848
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
4949
pub enum InternalRecordError {
50-
#[error("Truncated: {0}")]
50+
#[error("truncated: {0}")]
5151
Truncated(&'static str),
52-
#[error("Invalid value [{0}]: {1}")]
52+
#[error("invalid value [{0}]: {1}")]
5353
InvalidValue(&'static str, &'static str),
5454
}
5555

5656
/// `impl Display` can be safely returned to the client without leaking internal details.
5757
#[derive(Debug, PartialEq, thiserror::Error)]
5858
pub enum PublicRecordError {
59-
#[error("Unknown command")]
59+
#[error("unknown command")]
6060
UnknownCommand,
61-
#[error("Invalid `{0}` command: {1}")]
61+
#[error("invalid `{0}` command: {1}")]
6262
CommandPayload(CommandOp, CommandPayloadError),
63-
#[error("Invalid header: {0}")]
63+
#[error("invalid header: {0}")]
6464
Header(#[from] HeaderValidationError),
6565
}
6666

common/src/types/access.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ impl<T: StrProps> TryFrom<CompactString> for AccessTokenIdStr<T> {
7777

7878
fn try_from(name: CompactString) -> Result<Self, Self::Error> {
7979
if !T::IS_PREFIX && name.is_empty() {
80-
return Err(format!("Access token {} must not be empty", T::FIELD_NAME).into());
80+
return Err(format!("access token {} must not be empty", T::FIELD_NAME).into());
8181
}
8282

8383
if name.len() > Self::MAX_LENGTH {
8484
return Err(format!(
85-
"Access token {} must not exceed {} characters in length",
85+
"access token {} must not exceed {} characters in length",
8686
T::FIELD_NAME,
8787
Self::MAX_LENGTH
8888
)

common/src/types/basin.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<T: StrProps> TryFrom<CompactString> for BasinNameStr<T> {
7171
fn try_from(name: CompactString) -> Result<Self, Self::Error> {
7272
if name.len() > caps::MAX_BASIN_NAME_LEN {
7373
return Err(format!(
74-
"Basin {} must not exceed {} characters in length",
74+
"basin {} must not exceed {} characters in length",
7575
T::FIELD_NAME,
7676
caps::MAX_BASIN_NAME_LEN
7777
)
@@ -80,7 +80,7 @@ impl<T: StrProps> TryFrom<CompactString> for BasinNameStr<T> {
8080

8181
if !T::IS_PREFIX && name.len() < caps::MIN_BASIN_NAME_LEN {
8282
return Err(format!(
83-
"Basin {} should be at least {} characters in length",
83+
"basin {} should be at least {} characters in length",
8484
T::FIELD_NAME,
8585
caps::MIN_BASIN_NAME_LEN
8686
)
@@ -95,7 +95,7 @@ impl<T: StrProps> TryFrom<CompactString> for BasinNameStr<T> {
9595

9696
if !first_char.is_ascii_lowercase() && !first_char.is_ascii_digit() {
9797
return Err(format!(
98-
"Basin {} must begin with a lowercase letter or number",
98+
"basin {} must begin with a lowercase letter or number",
9999
T::FIELD_NAME
100100
)
101101
.into());
@@ -107,15 +107,15 @@ impl<T: StrProps> TryFrom<CompactString> for BasinNameStr<T> {
107107
&& !last_char.is_ascii_digit()
108108
{
109109
return Err(format!(
110-
"Basin {} must end with a lowercase letter or number",
110+
"basin {} must end with a lowercase letter or number",
111111
T::FIELD_NAME
112112
)
113113
.into());
114114
}
115115

116116
if chars.any(|c| !c.is_ascii_lowercase() && !c.is_ascii_digit() && c != '-') {
117117
return Err(format!(
118-
"Basin {} must comprise lowercase letters, numbers, and hyphens",
118+
"basin {} must comprise lowercase letters, numbers, and hyphens",
119119
T::FIELD_NAME
120120
)
121121
.into());

common/src/types/stream.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ impl<T: StrProps> TryFrom<CompactString> for StreamNameStr<T> {
7979

8080
fn try_from(name: CompactString) -> Result<Self, Self::Error> {
8181
if !T::IS_PREFIX && name.is_empty() {
82-
return Err(format!("Stream {} must not be empty", T::FIELD_NAME).into());
82+
return Err(format!("stream {} must not be empty", T::FIELD_NAME).into());
8383
}
8484

8585
if name.len() > caps::MAX_STREAM_NAME_LEN {
8686
return Err(format!(
87-
"Stream {} must not exceed {} characters in length",
87+
"stream {} must not exceed {} characters in length",
8888
T::FIELD_NAME,
8989
caps::MAX_STREAM_NAME_LEN
9090
)
@@ -199,7 +199,7 @@ impl TryFrom<AppendRecordParts> for AppendRecord {
199199

200200
fn try_from(parts: AppendRecordParts) -> Result<Self, Self::Error> {
201201
if parts.metered_size() > caps::RECORD_BATCH_MAX.bytes {
202-
Err("Record must have metered size less than 1 MiB")
202+
Err("record must have metered size less than 1 MiB")
203203
} else {
204204
Ok(Self(parts))
205205
}
@@ -237,15 +237,15 @@ impl TryFrom<Metered<Vec<AppendRecord>>> for AppendRecordBatch {
237237

238238
fn try_from(records: Metered<Vec<AppendRecord>>) -> Result<Self, Self::Error> {
239239
if records.is_empty() {
240-
return Err("Record batch must not be empty");
240+
return Err("record batch must not be empty");
241241
}
242242

243243
if records.len() > caps::RECORD_BATCH_MAX.count {
244-
return Err("Record batch must not exceed 1000 records");
244+
return Err("record batch must not exceed 1000 records");
245245
}
246246

247247
if records.metered_size() > caps::RECORD_BATCH_MAX.bytes {
248-
return Err("Record batch must not exceed a metered size of 1 MiB");
248+
return Err("record batch must not exceed a metered size of 1 MiB");
249249
}
250250

251251
Ok(Self(records))

0 commit comments

Comments
 (0)