Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont compare db string errors (fixes #1393) #3424

Merged
merged 3 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 3 additions & 12 deletions crates/api_crud/src/post/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,9 @@ impl PerformCrud for CreatePost {
.thumbnail_url(thumbnail_url)
.build();

let inserted_post = match Post::create(context.pool(), &post_form).await {
Ok(post) => post,
Err(e) => {
let err_type = if e.to_string() == "value too long for type character varying(200)" {
"post_title_too_long"
} else {
"couldnt_create_post"
};

return Err(LemmyError::from_error_message(e, err_type));
}
};
let inserted_post = Post::create(context.pool(), &post_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;

let inserted_post_id = inserted_post.id;
let protocol_and_hostname = context.settings().get_protocol_and_hostname();
Expand Down
13 changes: 3 additions & 10 deletions crates/api_crud/src/post/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,9 @@ impl PerformCrud for EditPost {
.build();

let post_id = data.post_id;
let res = Post::update(context.pool(), post_id, &post_form).await;
if let Err(e) = res {
let err_type = if e.to_string() == "value too long for type character varying(200)" {
"post_title_too_long"
} else {
"couldnt_update_post"
};

return Err(LemmyError::from_error_message(e, err_type));
}
Post::update(context.pool(), post_id, &post_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;

build_post_response(
context,
Expand Down
2 changes: 1 addition & 1 deletion crates/utils/src/utils/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use url::Url;
static VALID_ACTOR_NAME_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex"));
static VALID_POST_TITLE_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r".*\S{3,}.*").expect("compile regex"));
Lazy::new(|| Regex::new(r".*\S{3,200}.*").expect("compile regex"));
static VALID_MATRIX_ID_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex")
});
Expand Down