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

* Dont compare db string errors (fixes #1393)

* cargo fmt

---------

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
fix_clippy_assert
Nutomic 2023-07-03 17:59:49 +02:00 committed by GitHub
parent b8ee9315bc
commit e1494d4683
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 23 deletions

View File

@ -107,18 +107,9 @@ impl PerformCrud for CreatePost {
.thumbnail_url(thumbnail_url) .thumbnail_url(thumbnail_url)
.build(); .build();
let inserted_post = match Post::create(context.pool(), &post_form).await { let inserted_post = Post::create(context.pool(), &post_form)
Ok(post) => post, .await
Err(e) => { .map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;
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_id = inserted_post.id; let inserted_post_id = inserted_post.id;
let protocol_and_hostname = context.settings().get_protocol_and_hostname(); let protocol_and_hostname = context.settings().get_protocol_and_hostname();

View File

@ -96,16 +96,9 @@ impl PerformCrud for EditPost {
.build(); .build();
let post_id = data.post_id; let post_id = data.post_id;
let res = Post::update(context.pool(), post_id, &post_form).await; Post::update(context.pool(), post_id, &post_form)
if let Err(e) = res { .await
let err_type = if e.to_string() == "value too long for type character varying(200)" { .map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;
"post_title_too_long"
} else {
"couldnt_update_post"
};
return Err(LemmyError::from_error_message(e, err_type));
}
build_post_response( build_post_response(
context, context,

View File

@ -8,7 +8,7 @@ use url::Url;
static VALID_ACTOR_NAME_REGEX: Lazy<Regex> = static VALID_ACTOR_NAME_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex")); Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex"));
static VALID_POST_TITLE_REGEX: Lazy<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(|| { 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") Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex")
}); });