Skip to content

Commit 2af98cd

Browse files
committed
improve error messages for internal err
1 parent 8092429 commit 2af98cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+283
-260
lines changed

backend/windmill-api/src/ai.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,20 @@ mod openai {
142142
tracing::debug!("Adding user to request body");
143143
let mut json_body: HashMap<String, Box<RawValue>> = serde_json::from_slice(&body)
144144
.map_err(|e| {
145-
Error::InternalErr(format!("Failed to parse request body: {}", e))
145+
Error::internal_err(format!("Failed to parse request body: {}", e))
146146
})?;
147147

148148
let user_json_string = serde_json::Value::String(user.unwrap()).to_string(); // makes sure to escape characters
149149

150150
json_body.insert(
151151
"user".to_string(),
152152
RawValue::from_string(user_json_string)
153-
.map_err(|e| Error::InternalErr(format!("Failed to parse user: {}", e)))?,
153+
.map_err(|e| Error::internal_err(format!("Failed to parse user: {}", e)))?,
154154
);
155155

156156
body = serde_json::to_vec(&json_body)
157157
.map_err(|e| {
158-
Error::InternalErr(format!("Failed to reserialize request body: {}", e))
158+
Error::internal_err(format!("Failed to reserialize request body: {}", e))
159159
})?
160160
.into();
161161
}
@@ -204,13 +204,13 @@ mod openai {
204204
.send()
205205
.await
206206
.map_err(|err| {
207-
Error::InternalErr(format!(
207+
Error::internal_err(format!(
208208
"Failed to get OpenAI credentials using credentials flow: {}",
209209
err
210210
))
211211
})?;
212212
let response = response.json::<OpenaiCredentials>().await.map_err(|err| {
213-
Error::InternalErr(format!(
213+
Error::internal_err(format!(
214214
"Failed to parse OpenAI credentials from credentials flow: {}",
215215
err
216216
))
@@ -220,7 +220,7 @@ mod openai {
220220

221221
pub async fn get_cached_value(db: &DB, w_id: &str, resource: Value) -> Result<KeyCache> {
222222
let config = serde_json::from_value(resource)
223-
.map_err(|e| Error::InternalErr(format!("validating openai resource {e:#}")))?;
223+
.map_err(|e| Error::internal_err(format!("validating openai resource {e:#}")))?;
224224

225225
let mut user = None::<String>;
226226
let mut resource = match config {
@@ -257,7 +257,7 @@ mod openai {
257257
let azure_base_path = if let Some(azure_base_path) = azure_base_path {
258258
Some(
259259
serde_json::from_value::<String>(azure_base_path).map_err(|e| {
260-
Error::InternalErr(format!("validating openai azure base path {e:#}"))
260+
Error::internal_err(format!("validating openai azure base path {e:#}"))
261261
})?,
262262
)
263263
} else {
@@ -303,7 +303,7 @@ mod anthropic {
303303

304304
pub async fn get_cached_value(db: &DB, w_id: &str, resource: Value) -> Result<KeyCache> {
305305
let mut resource: AnthropicCache = serde_json::from_value(resource)
306-
.map_err(|e| Error::InternalErr(format!("validating anthropic resource {e:#}")))?;
306+
.map_err(|e| Error::internal_err(format!("validating anthropic resource {e:#}")))?;
307307
resource.api_key = get_variable_or_self(resource.api_key, db, w_id).await?;
308308
Ok(KeyCache::Anthropic(resource))
309309
}
@@ -335,7 +335,7 @@ mod mistral {
335335

336336
pub async fn get_cached_value(db: &DB, w_id: &str, resource: Value) -> Result<KeyCache> {
337337
let mut resource: MistralCache = serde_json::from_value(resource)
338-
.map_err(|e| Error::InternalErr(format!("validating mistral resource {e:#}")))?;
338+
.map_err(|e| Error::internal_err(format!("validating mistral resource {e:#}")))?;
339339
resource.api_key = get_variable_or_self(resource.api_key, db, w_id).await?;
340340
Ok(KeyCache::Mistral(resource))
341341
}
@@ -472,7 +472,7 @@ async fn proxy(
472472
.await?;
473473

474474
if ai_resource.is_none() {
475-
return Err(Error::InternalErr("AI resource not configured".to_string()));
475+
return Err(Error::internal_err("AI resource not configured".to_string()));
476476
}
477477

478478
let ai_resource = serde_json::from_value::<AIResource>(ai_resource.unwrap())
@@ -497,7 +497,7 @@ async fn proxy(
497497
};
498498

499499
if resource.is_none() {
500-
return Err(Error::InternalErr(format!(
500+
return Err(Error::internal_err(format!(
501501
"{:?} resource missing value",
502502
ai_provider
503503
)));

backend/windmill-api/src/apps.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ async fn list_apps(
360360
.fields(&["dm.deployment_msg"]);
361361
}
362362

363-
let sql = sqlb.sql().map_err(|e| Error::InternalErr(e.to_string()))?;
363+
let sql = sqlb.sql().map_err(|e| Error::internal_err(e.to_string()))?;
364364
let mut tx = user_db.begin(&authed).await?;
365365
let rows = sqlx::query_as::<_, ListableApp>(&sql)
366366
.fetch_all(&mut *tx)
@@ -611,7 +611,7 @@ async fn get_public_app_by_secret(
611611

612612
let decrypted = mc
613613
.decrypt_bytes_to_bytes(&(hex::decode(secret)?))
614-
.map_err(|e| Error::InternalErr(e.to_string()))?;
614+
.map_err(|e| Error::internal_err(e.to_string()))?;
615615
let bytes = str::from_utf8(&decrypted).map_err(to_anyhow)?;
616616

617617
let id: i64 = bytes.parse().map_err(to_anyhow)?;
@@ -958,7 +958,7 @@ async fn delete_app(
958958
.execute(&db)
959959
.await
960960
.map_err(|e| {
961-
Error::InternalErr(format!(
961+
Error::internal_err(format!(
962962
"error deleting deployment metadata for script with path {path} in workspace {w_id}: {e:#}"
963963
))
964964
})?;
@@ -1061,7 +1061,7 @@ async fn update_app(
10611061

10621062
sqlb.returning("path");
10631063

1064-
let sql = sqlb.sql().map_err(|e| Error::InternalErr(e.to_string()))?;
1064+
let sql = sqlb.sql().map_err(|e| Error::internal_err(e.to_string()))?;
10651065
let npath_o: Option<String> = sqlx::query_scalar(&sql).fetch_optional(&mut *tx).await?;
10661066
not_found_if_none(npath_o, "App", path)?
10671067
} else {
@@ -1710,7 +1710,7 @@ async fn upload_s3_file_from_app(
17101710
}
17111711
};
17121712

1713-
let s3_resource = s3_resource_opt.ok_or(Error::InternalErr(
1713+
let s3_resource = s3_resource_opt.ok_or(Error::internal_err(
17141714
"No files storage resource defined at the workspace level".to_string(),
17151715
))?;
17161716
let s3_client = build_object_store_client(&s3_resource).await?;
@@ -2034,7 +2034,10 @@ async fn build_args(
20342034
safe_args.insert(
20352035
k.to_string(),
20362036
to_raw_value(&value.unwrap_or(Ok(serde_json::Value::Null)).map_err(|e| {
2037-
Error::InternalErr(format!("failed to serialize ctx variable for {}: {}", k, e))
2037+
Error::internal_err(format!(
2038+
"failed to serialize ctx variable for {}: {}",
2039+
k, e
2040+
))
20382041
})?),
20392042
);
20402043
} else if !arg_str.contains("\"$var:") && !arg_str.contains("\"$res:") {
@@ -2054,7 +2057,7 @@ async fn build_args(
20542057
),
20552058
)
20562059
.map_err(|e| {
2057-
Error::InternalErr(format!(
2060+
Error::internal_err(format!(
20582061
"failed to remove sensitive variable(s)/resource(s) with error: {}",
20592062
e
20602063
))

backend/windmill-api/src/capture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ async fn get_capture_trigger_config_and_owner<T: DeserializeOwned>(
412412

413413
Ok((
414414
serde_json::from_str(trigger_config.get()).map_err(|e| {
415-
Error::InternalErr(format!(
415+
Error::internal_err(format!(
416416
"error parsing capture config for {} trigger: {}",
417417
kind, e
418418
))

backend/windmill-api/src/concurrency_groups.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use sql_builder::bind::Bind;
1616
use sql_builder::SqlBuilder;
1717
use uuid::Uuid;
1818
use windmill_common::db::UserDB;
19-
use windmill_common::error::Error::{InternalErr, PermissionDenied};
19+
use windmill_common::error::Error::PermissionDenied;
2020
use windmill_common::error::{self, JsonResult};
2121
use windmill_common::utils::require_admin;
2222

@@ -82,7 +82,7 @@ async fn prune_concurrency_group(
8282

8383
if n_job_uuids > 0 {
8484
tx.commit().await?;
85-
return Err(InternalErr(
85+
return Err(error::Error::internal_err(
8686
"Concurrency group is currently in use, unable to remove it. Retry later.".to_string(),
8787
));
8888
}

backend/windmill-api/src/embeddings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ async fn query_hub_scripts(
9090

9191
Ok(Json(results))
9292
} else {
93-
Err(windmill_common::error::Error::InternalErr(
93+
Err(windmill_common::error::Error::internal_err(
9494
"Embeddings db not initialized".to_string(),
9595
))
9696
}
@@ -124,7 +124,7 @@ async fn query_resource_types(
124124

125125
Ok(Json(results))
126126
} else {
127-
Err(windmill_common::error::Error::InternalErr(
127+
Err(windmill_common::error::Error::internal_err(
128128
"Embeddings db not initialized".to_string(),
129129
))
130130
}

backend/windmill-api/src/flows.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ async fn list_flows(
187187
.fields(&["dm.deployment_msg"]);
188188
}
189189

190-
let sql = sqlb.sql().map_err(|e| Error::InternalErr(e.to_string()))?;
190+
let sql = sqlb.sql().map_err(|e| Error::internal_err(e.to_string()))?;
191191
let mut tx = user_db.begin(&authed).await?;
192192
let rows = sqlx::query_as::<_, ListableFlow>(&sql)
193193
.fetch_all(&mut *tx)
@@ -704,7 +704,7 @@ async fn update_flow(
704704
w_id,
705705
)
706706
.execute(&mut *tx)
707-
.await.map_err(|e| error::Error::InternalErr(format!("Error updating flow due to flow update: {e:#}")))?;
707+
.await.map_err(|e| error::Error::internal_err(format!("Error updating flow due to flow update: {e:#}")))?;
708708

709709
if is_new_path {
710710
// if new path, must clone flow to new path and delete old flow for flow_version foreign key constraint
@@ -721,7 +721,7 @@ async fn update_flow(
721721
.execute(&mut *tx)
722722
.await
723723
.map_err(|e| {
724-
error::Error::InternalErr(format!("Error updating flow due to create new flow: {e:#}"))
724+
error::Error::internal_err(format!("Error updating flow due to create new flow: {e:#}"))
725725
})?;
726726

727727
sqlx::query!(
@@ -733,7 +733,7 @@ async fn update_flow(
733733
.execute(&mut *tx)
734734
.await
735735
.map_err(|e| {
736-
error::Error::InternalErr(format!(
736+
error::Error::internal_err(format!(
737737
"Error updating flow due to updating flow history path: {e:#}"
738738
))
739739
})?;
@@ -746,7 +746,7 @@ async fn update_flow(
746746
.execute(&mut *tx)
747747
.await
748748
.map_err(|e| {
749-
error::Error::InternalErr(format!(
749+
error::Error::internal_err(format!(
750750
"Error updating flow due to deleting old flow: {e:#}"
751751
))
752752
})?;
@@ -781,7 +781,7 @@ async fn update_flow(
781781
.fetch_one(&mut *tx)
782782
.await
783783
.map_err(|e| {
784-
error::Error::InternalErr(format!(
784+
error::Error::internal_err(format!(
785785
"Error updating flow due to flow history insert: {e:#}"
786786
))
787787
})?;
@@ -805,15 +805,15 @@ async fn update_flow(
805805
.bind(&flow_path)
806806
.bind(&w_id)
807807
.fetch_all(&mut *tx)
808-
.await.map_err(|e| error::Error::InternalErr(format!("Error updating flow due to related schedules update: {e:#}")))?;
808+
.await.map_err(|e| error::Error::internal_err(format!("Error updating flow due to related schedules update: {e:#}")))?;
809809

810810
let schedule = sqlx::query_as::<_, Schedule>(
811811
"UPDATE schedule SET path = $1, script_path = $1 WHERE path = $2 AND workspace_id = $3 AND is_flow IS true RETURNING *")
812812
.bind(&nf.path)
813813
.bind(&flow_path)
814814
.bind(&w_id)
815815
.fetch_optional(&mut *tx)
816-
.await.map_err(|e| error::Error::InternalErr(format!("Error updating flow due to related schedule update: {e:#}")))?;
816+
.await.map_err(|e| error::Error::internal_err(format!("Error updating flow due to related schedule update: {e:#}")))?;
817817

818818
if let Some(schedule) = schedule {
819819
clear_schedule(&mut tx, &flow_path, &w_id).await?;
@@ -907,7 +907,7 @@ async fn update_flow(
907907
.execute(&mut *new_tx)
908908
.await
909909
.map_err(|e| {
910-
error::Error::InternalErr(format!(
910+
error::Error::internal_err(format!(
911911
"Error updating flow due to updating dependency job field: {e:#}"
912912
))
913913
})?;
@@ -919,7 +919,7 @@ async fn update_flow(
919919
.execute(&mut *new_tx)
920920
.await
921921
.map_err(|e| {
922-
error::Error::InternalErr(format!(
922+
error::Error::internal_err(format!(
923923
"Error updating flow due to cancelling dependency job: {e:#}"
924924
))
925925
})?;
@@ -1204,7 +1204,7 @@ async fn delete_flow_by_path(
12041204
.execute(&db)
12051205
.await
12061206
.map_err(|e| {
1207-
Error::InternalErr(format!(
1207+
Error::internal_err(format!(
12081208
"error deleting deployment metadata for script with path {path} in workspace {w_id}: {e:#}"
12091209
))
12101210
})?;

backend/windmill-api/src/folders.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ async fn update_folder(
340340

341341
let sql = sqlb
342342
.sql()
343-
.map_err(|e| error::Error::InternalErr(e.to_string()))?;
343+
.map_err(|e| error::Error::internal_err(e.to_string()))?;
344344
let nfolder = sqlx::query_as::<_, Folder>(&sql)
345345
.fetch_optional(&mut *tx)
346346
.await?;

backend/windmill-api/src/http_triggers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async fn list_triggers(
176176
}
177177
let sql = sqlb
178178
.sql()
179-
.map_err(|e| error::Error::InternalErr(e.to_string()))?;
179+
.map_err(|e| error::Error::internal_err(e.to_string()))?;
180180
let rows = sqlx::query_as::<_, Trigger>(&sql)
181181
.fetch_all(&mut *tx)
182182
.await?;
@@ -590,7 +590,7 @@ async fn route_job(
590590

591591
#[cfg(not(feature = "parquet"))]
592592
if trigger.static_asset_config.is_some() {
593-
return error::Error::InternalErr(
593+
return error::Error::internal_err(
594594
"Static asset configuration is not supported in this build".to_string(),
595595
)
596596
.into_response();
@@ -608,14 +608,14 @@ async fn route_job(
608608
config.storage,
609609
)
610610
.await?;
611-
let s3_resource = s3_resource_opt.ok_or(error::Error::InternalErr(
611+
let s3_resource = s3_resource_opt.ok_or(error::Error::internal_err(
612612
"No files storage resource defined at the workspace level".to_string(),
613613
))?;
614614
let s3_client = build_object_store_client(&s3_resource).await?;
615615
let path = object_store::path::Path::from(config.s3);
616616
let s3_object = s3_client.get(&path).await.map_err(|err| {
617617
tracing::warn!("Error retrieving file from S3: {:?}", err);
618-
error::Error::InternalErr(format!("Error retrieving file: {}", err.to_string()))
618+
error::Error::internal_err(format!("Error retrieving file: {}", err.to_string()))
619619
})?;
620620
let mut response_headers = http::HeaderMap::new();
621621
if let Some(ref e_tag) = s3_object.meta.e_tag {

backend/windmill-api/src/job_helpers_ee.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub async fn get_s3_resource<'c>(
6969
_resource_type: Option<StorageResourceType>,
7070
_job_id: Option<Uuid>,
7171
) -> error::Result<ObjectStoreResource> {
72-
Err(error::Error::InternalErr(
72+
Err(error::Error::internal_err(
7373
"Not implemented in Windmill's Open Source repository".to_string(),
7474
))
7575
}
@@ -81,7 +81,7 @@ pub async fn upload_file_from_req(
8181
_req: axum::extract::Request,
8282
_options: PutMultipartOpts,
8383
) -> error::Result<()> {
84-
Err(error::Error::InternalErr(
84+
Err(error::Error::internal_err(
8585
"Not implemented in Windmill's Open Source repository".to_string(),
8686
))
8787
}
@@ -93,7 +93,7 @@ pub async fn upload_file_internal(
9393
_stream: impl Stream<Item = Result<Bytes, std::io::Error>> + Unpin,
9494
_options: PutMultipartOpts,
9595
) -> error::Result<()> {
96-
Err(error::Error::InternalErr(
96+
Err(error::Error::internal_err(
9797
"Not implemented in Windmill's Open Source repository".to_string(),
9898
))
9999
}
@@ -107,7 +107,7 @@ pub async fn download_s3_file_internal(
107107
_w_id: &str,
108108
_query: DownloadFileQuery,
109109
) -> error::Result<Response> {
110-
Err(error::Error::InternalErr(
110+
Err(error::Error::internal_err(
111111
"Not implemented in Windmill's Open Source repository".to_string(),
112112
))
113113
}
@@ -120,7 +120,7 @@ pub async fn load_image_preview_internal(
120120
_w_id: &str,
121121
_query: LoadImagePreviewQuery,
122122
) -> error::Result<Response> {
123-
Err(error::Error::InternalErr(
123+
Err(error::Error::internal_err(
124124
"Not implemented in Windmill's Open Source repository".to_string(),
125125
))
126126
}

0 commit comments

Comments
 (0)