Skip to content

Commit f8922bb

Browse files
nipunn1313Convex, Inc.
authored andcommitted
Give user facing error messages when there are bad paths (#35871)
Make ModulePath::components() fallible Give user facing error messages when there are bad paths Eg ✖ Error: Unable to start push to http://127.0.0.1:8000 Invalid component "_" in module path mastra/_ GitOrigin-RevId: 1391bcbf35bbdb8b2a210072ad50ae8132b142cf
1 parent 74853aa commit f8922bb

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

crates/convex/sync_types/src/module_path.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ impl ModulePath {
6868
self.path.components().map(|component| match component {
6969
Component::Normal(c) => c
7070
.to_str()
71-
.context("Non-unicode data in module path?")?
71+
.with_context(|| format!("Non-unicode data in module path {}", self.as_str()))?
7272
.parse()
73-
.context("Invalid component in module path"),
74-
c => anyhow::bail!("Unexpected component {c:?}"),
73+
.with_context(|| {
74+
format!("Invalid component {c:?} in module path {}", self.as_str())
75+
}),
76+
c => anyhow::bail!(
77+
"Unexpected component {c:?} in module path {}",
78+
self.as_str()
79+
),
7580
})
7681
}
7782

crates/model/src/components/file_based_routing.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ pub fn file_based_exports(
2828
for (module_path, module) in functions {
2929
let stripped = module_path.clone().strip();
3030

31-
let identifiers = stripped.components().collect::<anyhow::Result<Vec<_>>>()?;
31+
let identifiers = stripped
32+
.components()
33+
.collect::<anyhow::Result<Vec<_>>>()
34+
.or_else(|e| {
35+
anyhow::bail!(ErrorMetadata::bad_request(
36+
"InvalidModulePath",
37+
e.to_string()
38+
))
39+
})?;
3240
for function in &module.functions {
3341
if function.visibility != Some(Visibility::Public) {
3442
continue;

0 commit comments

Comments
 (0)