Skip to content

Commit f448b5f

Browse files
committed
fix: replace assert! in AcceptHeader::new with Result
The assert! panicked at runtime when OpenAPI specs had endpoints with empty content type strings. AcceptHeader::new now returns Result<Self> like all other validated newtypes in the codebase.
1 parent 001e594 commit f448b5f

6 files changed

Lines changed: 15 additions & 7 deletions

File tree

crates/sqlize-core/src/catalog/ddl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ mod tests {
114114
method: HttpMethod::Get,
115115
path: PathTemplate::new("/repos/{owner}/{repo}/issues").unwrap(),
116116
base_url: BaseUrl::new("https://api.github.com").unwrap(),
117-
accept: AcceptHeader::new("application/json"),
117+
accept: AcceptHeader::new("application/json").unwrap(),
118118
response_wrapper_key: None,
119119
},
120120
}

crates/sqlize-core/src/catalog/types.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,15 @@ impl fmt::Display for HttpMethod {
316316
pub struct AcceptHeader(String);
317317

318318
impl AcceptHeader {
319-
pub fn new(s: impl Into<String>) -> Self {
319+
pub fn new(s: impl Into<String>) -> Result<Self, Error> {
320320
let s = s.into();
321-
assert!(!s.is_empty(), "AcceptHeader cannot be empty");
322-
Self(s)
321+
if s.is_empty() {
322+
return Err(Error::InvalidAcceptHeader {
323+
input: s,
324+
reason: "cannot be empty",
325+
});
326+
}
327+
Ok(Self(s))
323328
}
324329

325330
pub fn as_str(&self) -> &str {

crates/sqlize-core/src/datafusion/arrow_convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ mod tests {
312312
method: HttpMethod::Get,
313313
path: PathTemplate::new("/test").unwrap(),
314314
base_url: BaseUrl::new("https://example.com").unwrap(),
315-
accept: AcceptHeader::new("application/json"),
315+
accept: AcceptHeader::new("application/json").unwrap(),
316316
response_wrapper_key: None,
317317
},
318318
}

crates/sqlize-core/src/datafusion/provider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ mod tests {
215215
method: HttpMethod::Get,
216216
path: PathTemplate::new("/test/{id}").unwrap(),
217217
base_url: BaseUrl::new("https://example.com").unwrap(),
218-
accept: AcceptHeader::new("application/json"),
218+
accept: AcceptHeader::new("application/json").unwrap(),
219219
response_wrapper_key: None,
220220
},
221221
}

crates/sqlize-core/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ pub enum Error {
2020
#[error("invalid base URL {input:?}: {reason}")]
2121
InvalidBaseUrl { input: String, reason: &'static str },
2222

23+
#[error("invalid accept header {input:?}: {reason}")]
24+
InvalidAcceptHeader { input: String, reason: &'static str },
25+
2326
// ---- Catalog lookup ----
2427
#[error("table {0} not found in catalog")]
2528
TableNotFound(TableName),

crates/sqlize-core/src/spec/table_gen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn try_build_table(
165165
method: HttpMethod::Get,
166166
path: path_template,
167167
base_url: base_url.clone(),
168-
accept: crate::catalog::types::AcceptHeader::new(content_type),
168+
accept: crate::catalog::types::AcceptHeader::new(content_type)?,
169169
response_wrapper_key: wrapper_key,
170170
},
171171
}))

0 commit comments

Comments
 (0)