Skip to content

Commit b881712

Browse files
gautamg795Convex, Inc.
authored andcommitted
rename NotFound error
GitOrigin-RevId: f74b563063286a05e86fbd3305f0a0c0df9d2c37
1 parent 39b2581 commit b881712

File tree

9 files changed

+56
-45
lines changed

9 files changed

+56
-45
lines changed

crates/application/src/lib.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ impl<RT: Runtime> Application<RT> {
13941394
.completed_export_at_ts(snapshot_ts)
13951395
.await?;
13961396
let export: ParsedDocument<Export> = export_doc
1397-
.context(ErrorMetadata::transient_not_found(
1397+
.context(ErrorMetadata::not_found(
13981398
"ExportNotFound",
13991399
format!("The requested export {snapshot_ts} was not found"),
14001400
))?
@@ -1409,12 +1409,14 @@ impl<RT: Runtime> Application<RT> {
14091409
},
14101410
}
14111411
};
1412-
let storage_get_stream = self.exports_storage.get(&object_key).await?.context(
1413-
ErrorMetadata::transient_not_found(
1414-
"ExportNotFound",
1415-
format!("The requested export {snapshot_ts}/{object_key:?} was not found"),
1416-
),
1417-
)?;
1412+
let storage_get_stream =
1413+
self.exports_storage
1414+
.get(&object_key)
1415+
.await?
1416+
.context(ErrorMetadata::not_found(
1417+
"ExportNotFound",
1418+
format!("The requested export {snapshot_ts}/{object_key:?} was not found"),
1419+
))?;
14181420
Ok(storage_get_stream)
14191421
}
14201422

@@ -2468,7 +2470,7 @@ impl<RT: Runtime> Application<RT> {
24682470
.get_file_entry(&mut file_storage_tx, component.into(), storage_id.clone())
24692471
.await?
24702472
else {
2471-
return Err(ErrorMetadata::transient_not_found(
2473+
return Err(ErrorMetadata::not_found(
24722474
"FileNotFound",
24732475
format!("File {storage_id} not found"),
24742476
)
@@ -2491,14 +2493,14 @@ impl<RT: Runtime> Application<RT> {
24912493
.get_file_entry(&mut file_storage_tx, component.into(), storage_id.clone())
24922494
.await?
24932495
else {
2494-
return Err(ErrorMetadata::transient_not_found(
2496+
return Err(ErrorMetadata::not_found(
24952497
"FileNotFound",
24962498
format!("File {storage_id} not found"),
24972499
)
24982500
.into());
24992501
};
25002502
let Some(component_path) = file_storage_tx.get_component_path(component) else {
2501-
return Err(ErrorMetadata::transient_not_found(
2503+
return Err(ErrorMetadata::not_found(
25022504
"FileNotFound",
25032505
format!("Component {component:?} not found"),
25042506
)
@@ -2528,14 +2530,14 @@ impl<RT: Runtime> Application<RT> {
25282530
.get_file_entry(&mut file_storage_tx, component.into(), storage_id.clone())
25292531
.await?
25302532
else {
2531-
return Err(ErrorMetadata::transient_not_found(
2533+
return Err(ErrorMetadata::not_found(
25322534
"FileNotFound",
25332535
format!("File {storage_id} not found"),
25342536
)
25352537
.into());
25362538
};
25372539
let Some(component_path) = file_storage_tx.get_component_path(component) else {
2538-
return Err(ErrorMetadata::transient_not_found(
2540+
return Err(ErrorMetadata::not_found(
25392541
"FileNotFound",
25402542
format!("Component {component:?} not found"),
25412543
)

crates/application/src/snapshot_import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ async fn wait_for_import_worker<RT: Runtime>(
15011501
import_model
15021502
.get(import_id)
15031503
.await?
1504-
.context(ErrorMetadata::transient_not_found(
1504+
.context(ErrorMetadata::not_found(
15051505
"ImportNotFound",
15061506
format!("import {import_id} not found"),
15071507
))?;

crates/errors/src/lib.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub enum ErrorCode {
4545
BadRequest,
4646
Unauthenticated,
4747
Forbidden,
48-
TransientNotFound,
48+
NotFound,
4949
ClientDisconnect,
5050
RateLimited,
5151

@@ -91,17 +91,17 @@ impl ErrorMetadata {
9191
/// a deterministic user error. It should typically be used when the
9292
/// resource can't be currently found, e.g. the backend is not currently
9393
/// in service discovery. If the UDF is missing, this should throw
94-
/// `bad_request`` insteaFd, which is a deterministic user error.
94+
/// `bad_request`` instead, which is a deterministic user error.
9595
///
9696
/// The short_msg should be a CapitalCamelCased describing the error (eg
9797
/// FileNotFound). The msg should be a descriptive message targeted
9898
/// toward the developer.
99-
pub fn transient_not_found(
99+
pub fn not_found(
100100
short_msg: impl Into<Cow<'static, str>>,
101101
msg: impl Into<Cow<'static, str>>,
102102
) -> Self {
103103
Self {
104-
code: ErrorCode::TransientNotFound,
104+
code: ErrorCode::NotFound,
105105
short_msg: short_msg.into(),
106106
msg: msg.into(),
107107
}
@@ -331,8 +331,8 @@ impl ErrorMetadata {
331331
self.code == ErrorCode::BadRequest
332332
}
333333

334-
pub fn is_transient_not_found(&self) -> bool {
335-
self.code == ErrorCode::TransientNotFound
334+
pub fn is_not_found(&self) -> bool {
335+
self.code == ErrorCode::NotFound
336336
}
337337

338338
pub fn is_overloaded(&self) -> bool {
@@ -358,7 +358,7 @@ impl ErrorMetadata {
358358
| ErrorCode::Forbidden => true,
359359
ErrorCode::OperationalInternalServerError
360360
| ErrorCode::ClientDisconnect
361-
| ErrorCode::TransientNotFound
361+
| ErrorCode::NotFound
362362
| ErrorCode::RateLimited
363363
| ErrorCode::OCC
364364
| ErrorCode::OutOfRetention
@@ -377,7 +377,7 @@ impl ErrorMetadata {
377377
ErrorCode::ClientDisconnect => None,
378378
ErrorCode::RateLimited => Some((sentry::Level::Info, Some(0.01))),
379379
ErrorCode::BadRequest
380-
| ErrorCode::TransientNotFound
380+
| ErrorCode::NotFound
381381
| ErrorCode::PaginationLimit
382382
| ErrorCode::Unauthenticated
383383
| ErrorCode::Forbidden
@@ -402,7 +402,7 @@ impl ErrorMetadata {
402402
| ErrorCode::ClientDisconnect
403403
| ErrorCode::MisdirectedRequest
404404
| ErrorCode::RateLimited => None,
405-
ErrorCode::TransientNotFound => Some("transient_not_found"),
405+
ErrorCode::NotFound => Some("not_found"),
406406
ErrorCode::OCC => Some("occ"),
407407
ErrorCode::OutOfRetention => Some("out_of_retention"),
408408
ErrorCode::Overloaded => Some("overloaded"),
@@ -424,7 +424,7 @@ impl ErrorMetadata {
424424
ErrorCode::Unauthenticated => Some(&crate::metrics::SYNC_AUTH_ERROR_TOTAL),
425425
ErrorCode::Forbidden => Some(&crate::metrics::FORBIDDEN_ERROR_TOTAL),
426426
ErrorCode::OCC => Some(&crate::metrics::COMMIT_RACE_TOTAL),
427-
ErrorCode::TransientNotFound => None,
427+
ErrorCode::NotFound => None,
428428
ErrorCode::PaginationLimit => None,
429429
ErrorCode::OutOfRetention => None,
430430
ErrorCode::Overloaded => None,
@@ -436,7 +436,7 @@ impl ErrorMetadata {
436436

437437
pub fn close_frame(&self) -> Option<CloseFrame<'static>> {
438438
let code = match self.code {
439-
ErrorCode::TransientNotFound
439+
ErrorCode::NotFound
440440
| ErrorCode::PaginationLimit
441441
| ErrorCode::Forbidden
442442
| ErrorCode::ClientDisconnect => Some(CloseCode::Normal),
@@ -473,7 +473,7 @@ impl ErrorCode {
473473
// https://stackoverflow.com/questions/3297048/403-forbidden-vs-401-unauthorized-http-responses
474474
ErrorCode::Unauthenticated => StatusCode::UNAUTHORIZED,
475475
ErrorCode::Forbidden => StatusCode::FORBIDDEN,
476-
ErrorCode::TransientNotFound => StatusCode::NOT_FOUND,
476+
ErrorCode::NotFound => StatusCode::NOT_FOUND,
477477
ErrorCode::RateLimited => StatusCode::TOO_MANY_REQUESTS,
478478
ErrorCode::OperationalInternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
479479
ErrorCode::OCC
@@ -490,7 +490,7 @@ impl ErrorCode {
490490
ErrorCode::BadRequest => tonic::Code::InvalidArgument,
491491
ErrorCode::Unauthenticated => tonic::Code::Unauthenticated,
492492
ErrorCode::Forbidden => tonic::Code::FailedPrecondition,
493-
ErrorCode::TransientNotFound => tonic::Code::NotFound,
493+
ErrorCode::NotFound => tonic::Code::NotFound,
494494
ErrorCode::ClientDisconnect => tonic::Code::Aborted,
495495
ErrorCode::Overloaded | ErrorCode::RejectedBeforeExecution | ErrorCode::RateLimited => {
496496
tonic::Code::ResourceExhausted
@@ -507,7 +507,7 @@ impl ErrorCode {
507507
match code {
508508
StatusCode::UNAUTHORIZED => Some(ErrorCode::Unauthenticated),
509509
StatusCode::FORBIDDEN => Some(ErrorCode::Forbidden),
510-
StatusCode::NOT_FOUND => Some(ErrorCode::TransientNotFound),
510+
StatusCode::NOT_FOUND => Some(ErrorCode::NotFound),
511511
StatusCode::TOO_MANY_REQUESTS => Some(ErrorCode::RateLimited),
512512
StatusCode::MISDIRECTED_REQUEST => Some(ErrorCode::MisdirectedRequest),
513513
// Tries to categorize in one of the above more specific 4xx codes first,
@@ -525,7 +525,7 @@ pub trait ErrorMetadataAnyhowExt {
525525
fn is_unauthenticated(&self) -> bool;
526526
fn is_out_of_retention(&self) -> bool;
527527
fn is_bad_request(&self) -> bool;
528-
fn is_transient_not_found(&self) -> bool;
528+
fn is_not_found(&self) -> bool;
529529
fn is_overloaded(&self) -> bool;
530530
fn is_rejected_before_execution(&self) -> bool;
531531
fn is_forbidden(&self) -> bool;
@@ -587,9 +587,9 @@ impl ErrorMetadataAnyhowExt for anyhow::Error {
587587
}
588588

589589
/// Returns true if error is tagged as NotFound
590-
fn is_transient_not_found(&self) -> bool {
590+
fn is_not_found(&self) -> bool {
591591
if let Some(e) = self.downcast_ref::<ErrorMetadata>() {
592-
return e.is_transient_not_found();
592+
return e.is_not_found();
593593
}
594594
false
595595
}
@@ -795,7 +795,7 @@ mod proptest {
795795
fn arbitrary_with((): Self::Parameters) -> Self::Strategy {
796796
any::<ErrorCode>().prop_map(|ec| match ec {
797797
ErrorCode::BadRequest => ErrorMetadata::bad_request("bad", "request"),
798-
ErrorCode::TransientNotFound => ErrorMetadata::transient_not_found("not", "found"),
798+
ErrorCode::NotFound => ErrorMetadata::not_found("not", "found"),
799799
ErrorCode::PaginationLimit => {
800800
ErrorMetadata::pagination_limit("pagination", "limit")
801801
},
@@ -839,7 +839,7 @@ mod tests {
839839
// Error has visibility through sentry or custom metric.
840840
assert!(err.should_report_to_sentry().is_some() || err.custom_metric().is_some());
841841
if err.metric_server_error_label().is_some()
842-
&& err.code != ErrorCode::TransientNotFound {
842+
&& err.code != ErrorCode::NotFound {
843843
assert!(err.should_report_to_sentry().unwrap().0 >= sentry::Level::Warning);
844844
if err.code == ErrorCode::Overloaded ||
845845
err.code == ErrorCode::RejectedBeforeExecution {

crates/local_backend/src/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub async fn schema_state(
370370
.context(invalid_schema_id(&schema_id))?;
371371

372372
let doc = tx.get(schema_id).await?.ok_or_else(|| {
373-
anyhow::anyhow!(ErrorMetadata::transient_not_found(
373+
anyhow::anyhow!(ErrorMetadata::not_found(
374374
"SchemaNotFound",
375375
format!("Schema with id {} not found", schema_id),
376376
))

crates/model/src/components/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ impl<'a, RT: Runtime> ComponentConfigModel<'a, RT> {
719719
.load_component(component_id)
720720
.await?;
721721
let Some(component) = component else {
722-
anyhow::bail!(ErrorMetadata::transient_not_found(
722+
anyhow::bail!(ErrorMetadata::not_found(
723723
"ComponentNotFound",
724724
format!("Component with ID {:?} not found", component_id)
725725
));

crates/model/src/environment_variables/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl<'a, RT: Runtime> EnvironmentVariablesModel<'a, RT> {
221221
for (id, environment_variable) in changes.clone() {
222222
let new_env_var_name = environment_variable.name().to_owned();
223223
let document = self.tx.get(id).await?.ok_or_else(|| {
224-
ErrorMetadata::transient_not_found(
224+
ErrorMetadata::not_found(
225225
"ModifiedEnvVarNotFound",
226226
"The modified environment variable couldn’t be found.",
227227
)

crates/model/src/snapshot_imports/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'a, RT: Runtime> SnapshotImportModel<'a, RT> {
120120
let state = self
121121
.get(id)
122122
.await?
123-
.context(ErrorMetadata::transient_not_found(
123+
.context(ErrorMetadata::not_found(
124124
"ImportNotFound",
125125
format!("import {id} not found"),
126126
))?
@@ -162,13 +162,10 @@ impl<'a, RT: Runtime> SnapshotImportModel<'a, RT> {
162162
id: ResolvedDocumentId,
163163
update_checkpoints: impl FnOnce(&mut Vec<ImportTableCheckpoint>),
164164
) -> anyhow::Result<()> {
165-
let mut import = self
166-
.get(id)
167-
.await?
168-
.context(ErrorMetadata::transient_not_found(
169-
"ImportNotFound",
170-
format!("import {id} not found"),
171-
))?;
165+
let mut import = self.get(id).await?.context(ErrorMetadata::not_found(
166+
"ImportNotFound",
167+
format!("import {id} not found"),
168+
))?;
172169
let mut checkpoints = import.checkpoints.clone().unwrap_or_default();
173170
update_checkpoints(&mut checkpoints);
174171
import.checkpoints = Some(checkpoints);

crates/pb/src/error_metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl From<ErrorCode> for ErrorCodeProto {
1919
ErrorCode::BadRequest => ErrorCodeProto::BadRequest,
2020
ErrorCode::Unauthenticated => ErrorCodeProto::Unauthenticated,
2121
ErrorCode::Forbidden => ErrorCodeProto::Forbidden,
22-
ErrorCode::TransientNotFound => ErrorCodeProto::TransientNotFound,
22+
ErrorCode::NotFound => ErrorCodeProto::TransientNotFound,
2323
ErrorCode::ClientDisconnect => ErrorCodeProto::ClientDisconnect,
2424
ErrorCode::RateLimited => ErrorCodeProto::RateLimited,
2525
ErrorCode::Overloaded => ErrorCodeProto::Overloaded,
@@ -41,7 +41,7 @@ impl From<ErrorCodeProto> for ErrorCode {
4141
ErrorCodeProto::BadRequest => ErrorCode::BadRequest,
4242
ErrorCodeProto::Unauthenticated => ErrorCode::Unauthenticated,
4343
ErrorCodeProto::Forbidden => ErrorCode::Forbidden,
44-
ErrorCodeProto::TransientNotFound => ErrorCode::TransientNotFound,
44+
ErrorCodeProto::TransientNotFound => ErrorCode::NotFound,
4545
ErrorCodeProto::ClientDisconnect => ErrorCode::ClientDisconnect,
4646
ErrorCodeProto::RateLimited => ErrorCode::RateLimited,
4747
ErrorCodeProto::Overloaded => ErrorCode::Overloaded,

crates/runtime/src/prod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ impl ProdRuntime {
205205
let monitor = GLOBAL_TASK_MANAGER.lock().get(name);
206206
self.rt.block_on(monitor.instrument(f))
207207
}
208+
209+
/// Transitional function while we move away from using our own special
210+
/// `spawn`. Just wraps `tokio::spawn` with our tokio metrics
211+
/// integration.
212+
pub fn tokio_spawn<F>(name: &'static str, f: F) -> tokio::task::JoinHandle<F::Output>
213+
where
214+
F: Future + Send + 'static,
215+
F::Output: Send + 'static,
216+
{
217+
let monitor = GLOBAL_TASK_MANAGER.lock().get(name);
218+
tokio::spawn(monitor.instrument(f))
219+
}
208220
}
209221

210222
#[async_trait]

0 commit comments

Comments
 (0)