Skip to content

Commit 03cc6e5

Browse files
goffrieConvex, Inc.
authored and
Convex, Inc.
committed
Fix a bunch of ok_or(anyhow!())s (#37674)
GitOrigin-RevId: 6f6c24d141a73e226f2da110c64bc86b56710179
1 parent 9cec3db commit 03cc6e5

File tree

6 files changed

+29
-24
lines changed

6 files changed

+29
-24
lines changed

crates/isolate/src/environment/analyze.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ fn udf_analyze<RT: Runtime>(
664664
let resource_name_val = handler
665665
.get_script_origin()
666666
.resource_name()
667-
.ok_or(anyhow!("resource_name was None"))?;
667+
.context("resource_name was None")?;
668668
let resource_name = resource_name_val.to_rust_string_lossy(scope);
669669
let resource_url = module_specifier_from_str(&resource_name)?;
670670
let canon_path = path_from_module_specifier(&resource_url)?;
@@ -913,7 +913,7 @@ fn http_analyze<RT: Runtime>(
913913
let resource_name_val = handler
914914
.get_script_origin()
915915
.resource_name()
916-
.ok_or(anyhow!("resource_name was None"))?;
916+
.context("resource_name was None")?;
917917
let resource_name = resource_name_val.to_rust_string_lossy(scope);
918918
let resource_url = module_specifier_from_str(&resource_name)?;
919919
let canon_path = path_from_module_specifier(&resource_url)?;

crates/isolate/src/environment/helpers/module_loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ pub fn path_from_module_specifier(
104104
.parse::<CanonicalizedModulePath>()
105105
})
106106
.transpose()?
107-
.ok_or(anyhow!("module specifier did not start with {}", prefix))
107+
.ok_or_else(|| anyhow!("module specifier did not start with {}", prefix))
108108
}

crates/isolate/src/environment/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl SchemaEnvironment {
229229
let default_str = strings::default.create(&mut scope)?;
230230
let schema_val: v8::Local<v8::Value> = namespace
231231
.get(&mut scope, default_str.into())
232-
.ok_or(missing_schema_export_error())?;
232+
.ok_or_else(missing_schema_export_error)?;
233233
if schema_val.is_null_or_undefined() {
234234
anyhow::bail!(missing_schema_export_error());
235235
}

crates/local_backend/src/public_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pub async fn public_function_post_with_path(
274274
if path_parts.len() < 2 {
275275
return Err(bad_request_error().into());
276276
}
277-
let function_name = path_parts.pop().ok_or(bad_request_error())?;
277+
let function_name = path_parts.pop().ok_or_else(bad_request_error)?;
278278
let udf_path_str = format!("{}:{}", path_parts.join("/"), function_name);
279279
let udf_path = parse_udf_path(&udf_path_str)?;
280280
let udf_result = st

crates/model/src/fivetran_import/mod.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,20 @@ impl<'a, RT: Runtime> FivetranImportModel<'a, RT> {
158158
&& *index.name.descriptor() == *FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR
159159
&& index.is_database_index()
160160
})
161-
.ok_or(ErrorMetadata::bad_request(
162-
"MissingFivetranPrimaryKeyIndex",
163-
format!(
164-
"The `{}` index on the `{table_name}` table is missing. Please edit your \
165-
`schema.ts` file and add the following index to the `{table_name}` table: \
166-
.index(\"{}\", [/* …attributes in the primary key… */]) (or \
167-
.index(\"sync_index\", [\"fivetran.deleted\", /* …attributes in the primary \
168-
key… */]).",
169-
*FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR, *FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR,
170-
),
171-
))?;
161+
.ok_or_else(|| {
162+
ErrorMetadata::bad_request(
163+
"MissingFivetranPrimaryKeyIndex",
164+
format!(
165+
"The `{}` index on the `{table_name}` table is missing. Please edit your \
166+
`schema.ts` file and add the following index to the `{table_name}` \
167+
table: .index(\"{}\", [/* …attributes in the primary key… */]) (or \
168+
.index(\"sync_index\", [\"fivetran.deleted\", /* …attributes in the \
169+
primary key… */]).",
170+
*FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR,
171+
*FIVETRAN_PRIMARY_KEY_INDEX_DESCRIPTOR,
172+
),
173+
)
174+
})?;
172175

173176
let IndexConfig::Database {
174177
developer_config: DeveloperDatabaseIndexConfig { fields },
@@ -230,13 +233,15 @@ impl<'a, RT: Runtime> FivetranImportModel<'a, RT> {
230233
*index.name.table() == *table_name
231234
&& *index.name.descriptor() == *FIVETRAN_SYNCED_INDEX_DESCRIPTOR
232235
})
233-
.ok_or(ErrorMetadata::bad_request(
234-
"MissingFivetranSyncedIndex",
235-
format!(
236-
"The Fivetran synchronization index on the `{table_name}` table is missing. \
237-
Something went wrong with the Fivetran sync.",
238-
),
239-
))?;
236+
.ok_or_else(|| {
237+
ErrorMetadata::bad_request(
238+
"MissingFivetranSyncedIndex",
239+
format!(
240+
"The Fivetran synchronization index on the `{table_name}` table is \
241+
missing. Something went wrong with the Fivetran sync.",
242+
),
243+
)
244+
})?;
240245

241246
if !index.is_database_index() {
242247
anyhow::bail!("Unexpected index type");

crates/simulation/src/tests/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn assert_objects_match(expected: &ConvexObject, actual: &ConvexObject) -> anyho
5959
for (key, value) in expected.iter() {
6060
let actual_value = actual
6161
.get(key)
62-
.ok_or(anyhow::anyhow!("Key not found: {}", key))?;
62+
.ok_or_else(|| anyhow::anyhow!("Key not found: {}", key))?;
6363
_assert_results_match(value, actual_value)?;
6464
}
6565
Ok(())

0 commit comments

Comments
 (0)