Add error logging and explicit column list in queries
All checks were successful
ci/woodpecker/push/build Pipeline was successful

Explicit SELECT columns instead of SELECT * to avoid FromRow issues.
Add eprintln for S3 and DB errors to diagnose 500s.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mikhail Kilin
2026-03-18 14:53:55 +03:00
parent 3bddb0012d
commit 87eb93512b

View File

@@ -73,12 +73,17 @@ pub async fn get_project(
State(state): State<AppState>,
Path(id): Path<i32>,
) -> Result<Json<Project>, StatusCode> {
let project = sqlx::query_as::<_, Project>("SELECT * FROM projects WHERE id = $1")
.bind(id)
.fetch_optional(&state.pool)
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
.ok_or(StatusCode::NOT_FOUND)?;
let project = sqlx::query_as::<_, Project>(
"SELECT id, name, local, corp, content, file_name, file_key, file_size, created_at FROM projects WHERE id = $1",
)
.bind(id)
.fetch_optional(&state.pool)
.await
.map_err(|e| {
eprintln!("get_project DB error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})?
.ok_or(StatusCode::NOT_FOUND)?;
Ok(Json(project))
}
@@ -138,7 +143,10 @@ pub async fn update_project(
.bind(id)
.execute(&state.pool)
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
.map_err(|e| {
eprintln!("DB update error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})?;
// Handle file upload
if let Some((file_name, data)) = file_data {
@@ -157,11 +165,15 @@ pub async fn update_project(
let file_key = format!("projects/{}/{}", id, uuid::Uuid::new_v4());
let file_size = data.len() as i64;
state
.bucket
.put_object(&file_key, &data)
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let put_result = state.bucket.put_object(&file_key, &data).await;
match &put_result {
Ok(resp) => eprintln!("S3 put_object status: {}", resp.status_code()),
Err(e) => eprintln!("S3 put_object error: {}", e),
}
put_result.map_err(|e| {
eprintln!("S3 upload failed: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})?;
sqlx::query(
"UPDATE projects SET file_name = $1, file_key = $2, file_size = $3 WHERE id = $4",
@@ -210,7 +222,7 @@ pub async fn get_project_file(
State(state): State<AppState>,
Path(id): Path<i32>,
) -> Result<Response, StatusCode> {
let project = sqlx::query_as::<_, Project>("SELECT * FROM projects WHERE id = $1")
let project = sqlx::query_as::<_, Project>("SELECT id, name, local, corp, content, file_name, file_key, file_size, created_at FROM projects WHERE id = $1")
.bind(id)
.fetch_optional(&state.pool)
.await