Skip to content

Commit 2e49621

Browse files
committed
Merge branch 'release/v0.13.4'
2 parents fe27e58 + d6da329 commit 2e49621

File tree

16 files changed

+176
-81
lines changed

16 files changed

+176
-81
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
10+
## [[0.13.4]](https://github.com/thoth-pub/thoth/releases/tag/v0.13.4) - 2024-12-11
11+
### Added
12+
- [661](https://github.com/thoth-pub/thoth/pull/661) - Implement caching errors in export API
13+
914
## [[0.13.3]](https://github.com/thoth-pub/thoth/releases/tag/v0.13.3) - 2024-12-02
1015
### Changed
1116
- [660](https://github.com/thoth-pub/thoth/pull/660) - Upgrade rust to `1.83.0` in production `Dockerfile`

Cargo.lock

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "thoth"
3-
version = "0.13.3"
3+
version = "0.13.4"
44
authors = ["Javier Arias <javi@thoth.pub>", "Ross Higman <ross@thoth.pub>"]
55
edition = "2021"
66
license = "Apache-2.0"
@@ -15,11 +15,11 @@ maintenance = { status = "actively-developed" }
1515
members = ["thoth-api", "thoth-api-server", "thoth-app", "thoth-app-server", "thoth-client", "thoth-errors", "thoth-export-server"]
1616

1717
[dependencies]
18-
thoth-api = { version = "=0.13.3", path = "thoth-api", features = ["backend"] }
19-
thoth-api-server = { version = "=0.13.3", path = "thoth-api-server" }
20-
thoth-app-server = { version = "=0.13.3", path = "thoth-app-server" }
21-
thoth-errors = { version = "=0.13.3", path = "thoth-errors" }
22-
thoth-export-server = { version = "=0.13.3", path = "thoth-export-server" }
18+
thoth-api = { version = "=0.13.4", path = "thoth-api", features = ["backend"] }
19+
thoth-api-server = { version = "=0.13.4", path = "thoth-api-server" }
20+
thoth-app-server = { version = "=0.13.4", path = "thoth-app-server" }
21+
thoth-errors = { version = "=0.13.4", path = "thoth-errors" }
22+
thoth-export-server = { version = "=0.13.4", path = "thoth-export-server" }
2323
clap = { version = "4.5.21", features = ["cargo", "env"] }
2424
dialoguer = { version = "0.11.0", features = ["password"] }
2525
dotenv = "0.15.0"

thoth-api-server/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "thoth-api-server"
3-
version = "0.13.3"
3+
version = "0.13.4"
44
authors = ["Javier Arias <javi@thoth.pub>", "Ross Higman <ross@thoth.pub>"]
55
edition = "2021"
66
license = "Apache-2.0"
@@ -9,8 +9,8 @@ repository = "https://github.com/thoth-pub/thoth"
99
readme = "README.md"
1010

1111
[dependencies]
12-
thoth-api = { version = "=0.13.3", path = "../thoth-api", features = ["backend"] }
13-
thoth-errors = { version = "=0.13.3", path = "../thoth-errors" }
12+
thoth-api = { version = "=0.13.4", path = "../thoth-api", features = ["backend"] }
13+
thoth-errors = { version = "=0.13.4", path = "../thoth-errors" }
1414
actix-web = "4.9"
1515
actix-cors = "0.7.0"
1616
actix-http = "3.9.0"

thoth-api/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "thoth-api"
3-
version = "0.13.3"
3+
version = "0.13.4"
44
authors = ["Javier Arias <javi@thoth.pub>", "Ross Higman <ross@thoth.pub>"]
55
edition = "2021"
66
license = "Apache-2.0"
@@ -15,7 +15,7 @@ maintenance = { status = "actively-developed" }
1515
backend = ["diesel", "diesel-derive-enum", "diesel_migrations", "futures", "actix-web", "jsonwebtoken", "deadpool-redis"]
1616

1717
[dependencies]
18-
thoth-errors = { version = "=0.13.3", path = "../thoth-errors" }
18+
thoth-errors = { version = "=0.13.4", path = "../thoth-errors" }
1919
actix-web = { version = "4.9", optional = true }
2020
argon2rs = "0.2.5"
2121
isbn2 = "0.4.0"

thoth-api/src/model/subject/mod.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,13 @@ pub struct NewSubjectHistory {
123123
}
124124

125125
pub fn check_subject(subject_type: &SubjectType, code: &str) -> ThothResult<()> {
126-
let valid = match &subject_type {
127-
SubjectType::Bic => true,
128-
SubjectType::Bisac => true,
129-
SubjectType::Thema => THEMA_CODES.contains_key::<str>(code),
130-
SubjectType::Lcc => true,
131-
SubjectType::Custom => true,
132-
SubjectType::Keyword => true,
133-
};
134-
if valid {
135-
Ok(())
136-
} else {
137-
Err(ThothError::InvalidSubjectCode(
138-
code.to_string(),
139-
subject_type.to_string(),
140-
))
126+
if matches!(subject_type, SubjectType::Thema) && !THEMA_CODES.contains_key(code) {
127+
return Err(ThothError::InvalidSubjectCode {
128+
input: code.to_string(),
129+
subject_type: subject_type.to_string(),
130+
});
141131
}
132+
Ok(())
142133
}
143134

144135
impl Default for Subject {

thoth-api/src/redis.rs

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ pub async fn get(pool: &RedisPool, key: &str) -> ThothResult<String> {
2626
con.get(key).await.map_err(Into::into)
2727
}
2828

29+
pub async fn del(pool: &RedisPool, key: &str) -> ThothResult<String> {
30+
let mut con = create_connection(pool).await?;
31+
con.del(key).await.map_err(Into::into)
32+
}
33+
2934
#[cfg(test)]
3035
mod tests {
3136
use super::*;

thoth-app-server/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "thoth-app-server"
3-
version = "0.13.3"
3+
version = "0.13.4"
44
authors = ["Javier Arias <javi@thoth.pub>", "Ross Higman <ross@thoth.pub>"]
55
edition = "2021"
66
license = "Apache-2.0"

thoth-app/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "thoth-app"
3-
version = "0.13.3"
3+
version = "0.13.4"
44
authors = ["Javier Arias <javi@thoth.pub>", "Ross Higman <ross@thoth.pub>"]
55
edition = "2021"
66
license = "Apache-2.0"
@@ -29,8 +29,8 @@ semver = "1.0.23"
2929
serde = { version = "1.0", features = ["derive"] }
3030
serde_json = "1.0"
3131
uuid = { version = "1.11.0", features = ["serde", "v4", "js"] }
32-
thoth-api = { version = "=0.13.3", path = "../thoth-api" }
33-
thoth-errors = { version = "=0.13.3", path = "../thoth-errors" }
32+
thoth-api = { version = "=0.13.4", path = "../thoth-api" }
33+
thoth-errors = { version = "=0.13.4", path = "../thoth-errors" }
3434

3535
[build-dependencies]
3636
dotenv = "0.15.0"

thoth-client/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "thoth-client"
3-
version = "0.13.3"
3+
version = "0.13.4"
44
authors = ["Javier Arias <javi@thoth.pub>", "Ross Higman <ross@thoth.pub>"]
55
edition = "2021"
66
license = "Apache-2.0"
@@ -10,8 +10,8 @@ readme = "README.md"
1010
build = "build.rs"
1111

1212
[dependencies]
13-
thoth-api = {version = "=0.13.3", path = "../thoth-api" }
14-
thoth-errors = {version = "=0.13.3", path = "../thoth-errors" }
13+
thoth-api = {version = "=0.13.4", path = "../thoth-api" }
14+
thoth-errors = {version = "=0.13.4", path = "../thoth-errors" }
1515
graphql_client = "0.14.0"
1616
chrono = { version = "0.4.38", features = ["serde"] }
1717
reqwest = { version = "0.12", features = ["json"] }
@@ -22,4 +22,4 @@ serde_json = "1.0"
2222
uuid = { version = "1.11.0", features = ["serde"] }
2323

2424
[build-dependencies]
25-
thoth-api = { version = "=0.13.3", path = "../thoth-api", features = ["backend"] }
25+
thoth-api = { version = "=0.13.4", path = "../thoth-api", features = ["backend"] }

thoth-errors/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "thoth-errors"
3-
version = "0.13.3"
3+
version = "0.13.4"
44
authors = ["Javier Arias <javi@thoth.pub>", "Ross Higman <ross@thoth.pub>"]
55
edition = "2021"
66
license = "Apache-2.0"

thoth-errors/src/database_errors.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use phf::phf_map;
2-
use phf::Map;
1+
use phf::{phf_map, Map};
2+
use std::borrow::Cow;
33

44
use crate::ThothError;
55

@@ -173,7 +173,7 @@ impl From<diesel::result::Error> for ThothError {
173173
Error::DatabaseError(_kind, info) => {
174174
if let Some(constraint_name) = info.constraint_name() {
175175
if let Some(error) = DATABASE_CONSTRAINT_ERRORS.get(constraint_name) {
176-
return ThothError::DatabaseConstraintError(error);
176+
return ThothError::DatabaseConstraintError(Cow::Borrowed(error));
177177
}
178178
}
179179
ThothError::DatabaseError(info.message().to_string())
@@ -251,9 +251,9 @@ mod tests {
251251
DatabaseErrorKind::UniqueViolation,
252252
error_information
253253
)),
254-
ThothError::DatabaseConstraintError(
254+
ThothError::DatabaseConstraintError(Cow::Borrowed(
255255
"A contribution with this ordinal number already exists."
256-
)
256+
))
257257
)
258258
}
259259
#[test]

thoth-errors/src/lib.rs

+56-7
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
mod database_errors;
33

44
use core::convert::From;
5-
use serde::Deserialize;
6-
use std::fmt;
5+
use serde::{Deserialize, Serialize};
6+
use std::{borrow::Cow, fmt};
77
use thiserror::Error;
88

99
/// A specialised result type for returning Thoth data
10-
pub type ThothResult<T> = std::result::Result<T, ThothError>;
10+
pub type ThothResult<T> = Result<T, ThothError>;
1111

12-
#[derive(Error, Debug, PartialEq, Eq)]
12+
#[derive(Error, Debug, PartialEq, Eq, Serialize, Deserialize)]
1313
/// Represents anything that can go wrong in Thoth
1414
///
1515
/// This type is not intended to be exhaustively matched, and new variants may
1616
/// be added in the future without a major version bump.
1717
pub enum ThothError {
18-
#[error("{0} is not a valid {1} code")]
19-
InvalidSubjectCode(String, String),
18+
#[error("{input:?} is not a valid {subject_type:?} code")]
19+
InvalidSubjectCode { input: String, subject_type: String },
2020
#[error("Database error: {0}")]
2121
DatabaseError(String),
2222
#[error("Redis error: {0}")]
2323
RedisError(String),
2424
#[error("{0}")]
25-
DatabaseConstraintError(&'static str),
25+
DatabaseConstraintError(Cow<'static, str>),
2626
#[error("Internal error: {0}")]
2727
InternalError(String),
2828
#[error("Invalid credentials.")]
@@ -109,6 +109,18 @@ pub enum ThothError {
109109
ThothUpdateCanonicalError,
110110
}
111111

112+
impl ThothError {
113+
/// Serialise to JSON
114+
pub fn to_json(&self) -> ThothResult<String> {
115+
serde_json::to_string(&self).map_err(Into::into)
116+
}
117+
118+
/// Deserialise from JSON
119+
pub fn from_json(s: &str) -> ThothResult<ThothError> {
120+
serde_json::from_str(s).map_err(Into::into)
121+
}
122+
}
123+
112124
#[cfg(not(target_arch = "wasm32"))]
113125
impl juniper::IntoFieldError for ThothError {
114126
fn into_field_error(self) -> juniper::FieldError {
@@ -293,6 +305,12 @@ impl From<Box<dyn std::error::Error + Send + Sync>> for ThothError {
293305
}
294306
}
295307

308+
impl From<serde_json::Error> for ThothError {
309+
fn from(e: serde_json::Error) -> Self {
310+
ThothError::InternalError(e.to_string())
311+
}
312+
}
313+
296314
#[cfg(test)]
297315
mod tests {
298316
use super::*;
@@ -331,4 +349,35 @@ mod tests {
331349
ThothError::GraphqlError("A relation with this ordinal already exists.".to_string())
332350
)
333351
}
352+
353+
#[test]
354+
fn test_round_trip_serialisation() {
355+
let original_error = ThothError::InvalidSubjectCode {
356+
input: "002".to_string(),
357+
subject_type: "BIC".to_string(),
358+
};
359+
let json = original_error.to_json().unwrap();
360+
let deserialised_error = ThothError::from_json(&json).unwrap();
361+
assert_eq!(original_error, deserialised_error);
362+
}
363+
364+
#[test]
365+
fn test_to_json_valid_error() {
366+
let error = ThothError::InvalidSubjectCode {
367+
input: "001".to_string(),
368+
subject_type: "BIC".to_string(),
369+
};
370+
let json = error.to_json().unwrap();
371+
372+
assert!(json.contains("\"InvalidSubjectCode\""));
373+
assert!(json.contains("\"001\""));
374+
assert!(json.contains("\"BIC\""));
375+
}
376+
377+
#[test]
378+
fn test_invalid_json_deserialisation() {
379+
let invalid_json = r#"{"UnknownError":"Unexpected field"}"#;
380+
let error = ThothError::from_json(invalid_json);
381+
assert!(error.is_err());
382+
}
334383
}

thoth-export-server/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "thoth-export-server"
3-
version = "0.13.3"
3+
version = "0.13.4"
44
authors = ["Javier Arias <javi@thoth.pub>", "Ross Higman <ross@thoth.pub>"]
55
edition = "2021"
66
license = "Apache-2.0"
@@ -10,9 +10,9 @@ readme = "README.md"
1010
build = "build.rs"
1111

1212
[dependencies]
13-
thoth-api = { version = "=0.13.3", path = "../thoth-api" }
14-
thoth-errors = { version = "=0.13.3", path = "../thoth-errors" }
15-
thoth-client = { version = "=0.13.3", path = "../thoth-client" }
13+
thoth-api = { version = "=0.13.4", path = "../thoth-api" }
14+
thoth-errors = { version = "=0.13.4", path = "../thoth-errors" }
15+
thoth-client = { version = "=0.13.4", path = "../thoth-client" }
1616
actix-web = "4.9"
1717
actix-cors = "0.7.0"
1818
cc_license = "0.1.0"

0 commit comments

Comments
 (0)