Avoid panics #392

Слито
elegaanz слито 8 коммит(ов) из result в master 5 лет назад
elegaanz прокомментировал(а) 5 лет назад (Перенесено из github.com)
  • Use Result as much as possible
  • Display errors instead of panicking

TODO (maybe in another PR? this one is already quite big):

  • Find a way to merge Ructe/ErrorPage types, so that we can have routes returning Result<X, ErrorPage> instead of panicking when we have an Error
  • Display more details about the error, to make it easier to debug

(sorry, this isn't going to be fun to review, the diff is huge, but it is always the same changes)

- Use `Result` as much as possible - Display errors instead of panicking TODO (maybe in another PR? this one is already quite big): - Find a way to merge Ructe/ErrorPage types, so that we can have routes returning `Result<X, ErrorPage>` instead of panicking when we have an `Error` - Display more details about the error, to make it easier to debug (sorry, this isn't going to be fun to review, the diff is huge, but it is always the same changes)
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

(sorry, this isn't going to be fun to review, the diff is huge, but it is always the same changes)

I guess it wasn't fun to write either

> (sorry, this isn't going to be fun to review, the diff is huge, but it is always the same changes) I guess it wasn't fun to write either
igalic (Перенесено из github.com) рассмотрел(а) изменения 5 лет назад
igalic (Перенесено из github.com) оставил комментарий

first pass, not done yet

first pass, not done yet
@ -122,3 +122,3 @@
act["@context"] = context();
let signed = act.sign(sender);
let signed = act.sign(sender).expect("activity_pub::broadcast: signature error");
igalic (Перенесено из github.com) прокомментировал(а) 5 лет назад

i thought we're trying to avoid panics?

i thought we're trying to avoid panics?
@ -107,3 +107,3 @@
pub fn signature<S: Signer>(signer: &S, headers: &HeaderMap) -> HeaderValue {
pub fn signature<S: Signer>(signer: &S, headers: &HeaderMap) -> Result<HeaderValue, ()> {
let signed_string = headers
igalic (Перенесено из github.com) прокомментировал(а) 5 лет назад

can you briefly explain this return signature?
maybe then I'll also understand the above expect()

can you briefly explain this return signature? maybe then I'll also understand the above `expect()`
@ -214,0 +170,4 @@
// We don't really care about all the following for remote instances
long_description: SafeString::new(""),
short_description: SafeString::new(""),
default_license: String::new(),
igalic (Перенесено из github.com) прокомментировал(а) 5 лет назад

wow! that's some really nice refactoring! 👍

wow! that's some really nice refactoring! 👍
igalic (Перенесено из github.com) прокомментировал(а) 5 лет назад

so, it's ok, or desired, that tests panic, right?

so, it's ok, or desired, that tests panic, right?
igalic (Перенесено из github.com) прокомментировал(а) 5 лет назад

neat!

neat!
igalic (Перенесено из github.com) прокомментировал(а) 5 лет назад

https://doc.rust-lang.org/std/result/enum.Result.html#method.map_err i read the doc, but still don't understand what this does

https://doc.rust-lang.org/std/result/enum.Result.html#method.map_err i read the doc, but still don't understand what this does
trinity-1686a рассмотрел(а) изменения 5 лет назад
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

I you understand map, this is basically the same thing, but for Err(_) instead of Ok(_). And passing Error::from is the equivalent to |e| e.from()
This is just mapping an error type to another

I you understand `map`, this is basically the same thing, but for `Err(_)` instead of `Ok(_)`. And passing `Error::from` is the equivalent to `|e| e.from()` This is just mapping an error type to another
elegaanz (Перенесено из github.com) рассмотрел(а) изменения 5 лет назад
@ -122,3 +122,3 @@
act["@context"] = context();
let signed = act.sign(sender);
let signed = act.sign(sender).expect("activity_pub::broadcast: signature error");
elegaanz (Перенесено из github.com) прокомментировал(а) 5 лет назад

Ahah, right… It actually doesn't add a panic, we just panic "outside" of the function instead of "inside" because it wouldn't make much sense to return a Result from broadcast as it is always the main function of its thread.

Ahah, right… It actually doesn't add a panic, we just panic "outside" of the function instead of "inside" because it wouldn't make much sense to return a `Result` from `broadcast` as it is always the main function of its thread.
elegaanz (Перенесено из github.com) рассмотрел(а) изменения 5 лет назад
@ -107,3 +107,3 @@
pub fn signature<S: Signer>(signer: &S, headers: &HeaderMap) -> HeaderValue {
pub fn signature<S: Signer>(signer: &S, headers: &HeaderMap) -> Result<HeaderValue, ()> {
let signed_string = headers
elegaanz (Перенесено из github.com) прокомментировал(а) 5 лет назад

It says that it can either success with a HeaderValue, or fail with (), so we don't have much details about the error, we just know it failed, but it is probably enough to know that something failed in this function (or maybe not?)

It says that it can either success with a `HeaderValue`, or fail with `()`, so we don't have much details about the error, we just know it failed, but it is probably enough to know that something failed in this function (or maybe not?)
elegaanz (Перенесено из github.com) рассмотрел(а) изменения 5 лет назад
elegaanz (Перенесено из github.com) прокомментировал(а) 5 лет назад

Yes, tests should panic every time something is wrong, so that they fail and that we now something is broken.

Yes, tests should panic every time something is wrong, so that they fail and that we now something is broken.
codecov[bot] прокомментировал(а) 5 лет назад (Перенесено из github.com)

Codecov Report

Merging #392 into master will increase coverage by 0.08%.
The diff coverage is 19.5%.

@@            Coverage Diff             @@
##           master     #392      +/-   ##
==========================================
+ Coverage   27.76%   27.85%   +0.08%     
==========================================
  Files          63       63              
  Lines        6302     7260     +958     
==========================================
+ Hits         1750     2022     +272     
- Misses       4552     5238     +686
# [Codecov](https://codecov.io/gh/Plume-org/Plume/pull/392?src=pr&el=h1) Report > Merging [#392](https://codecov.io/gh/Plume-org/Plume/pull/392?src=pr&el=desc) into [master](https://codecov.io/gh/Plume-org/Plume/commit/e2d5a5057c2009e25cbb0f5625de0d0ebe7875ca?src=pr&el=desc) will **increase** coverage by `0.08%`. > The diff coverage is `19.5%`. ```diff @@ Coverage Diff @@ ## master #392 +/- ## ========================================== + Coverage 27.76% 27.85% +0.08% ========================================== Files 63 63 Lines 6302 7260 +958 ========================================== + Hits 1750 2022 +272 - Misses 4552 5238 +686 ```
trinity-1686a рассмотрел(а) изменения 5 лет назад
trinity-1686a оставил комментарий
Владелец

It seems good.
Some Result could/should be Result<()> instead.
The ? syntax is really helpful with error handling

It seems good. Some Result<T> could/should be Result<()> instead. The `?` syntax is really helpful with error handling
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

I could see a use for knowing how many posts were deleted, and at first at assumed it's what it was. But after re-reading it's telling how many blogs where deleted, so the Ok(_) will only be 1 any, am I right?

I could see a use for knowing how many posts were deleted, and at first at assumed it's what it was. But after re-reading it's telling how many blogs where deleted, so the Ok(_) will only be 1 any, am I right?
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

If I'm not mistaken, the usize is going to be how many entries were affected, which is one?

If I'm not mistaken, the usize is going to be how many entries were affected, which is one?
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

If I'm not mistaken, the usize is going to be how many entries were affected, which is one?

If I'm not mistaken, the usize is going to be how many entries were affected, which is one?
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

I don't know if there are other places where unwrap_or_else(|_| ..) was replaced with unwrap_or(..), if so this comment also apply to them. I think it would be better to or_else(|_| ..)?, I think you already did it at other places

I don't know if there are other places where `unwrap_or_else(|_| ..)` was replaced with `unwrap_or(..)`, if so this comment also apply to them. I think it would be better to `or_else(|_| ..)?`, I think you already did it at other places
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

Same about returning Result<()> because it will be 1

Same about returning Result<()> because it will be 1
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

same about Result<()>

same about `Result<()>`
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

Same about Result<()>

Same about `Result<()>`
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

Same about Result<()>

Same about `Result<()>`
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

I should have made this message from the start. Maybe add something about making sure no other instance of plume is already running here?

I should have made this message from the start. Maybe add something about making sure no other instance of plume is already running here?
elegaanz (Перенесено из github.com) рассмотрел(а) изменения 5 лет назад
elegaanz (Перенесено из github.com) прокомментировал(а) 5 лет назад

Yes, this result is not used anywhere, it just to have the right return type without having to .map(|_| ()), but maybe it's misleading?

Yes, this result is not used anywhere, it just to have the right return type without having to `.map(|_| ())`, but maybe it's misleading?
elegaanz (Перенесено из github.com) рассмотрел(а) изменения 5 лет назад
elegaanz (Перенесено из github.com) прокомментировал(а) 5 лет назад
Yes, but https://github.com/Plume-org/Plume/pull/392#discussion_r244369771
trinity-1686a рассмотрел(а) изменения 5 лет назад
trinity-1686a прокомментировал(а) 5 лет назад
Владелец

I think it is, even more because we did not document any function (nor what they return)

I think it is, even more because we did not document any function (nor what they return)
elegaanz (Перенесено из github.com) рассмотрел(а) изменения 5 лет назад
elegaanz (Перенесено из github.com) прокомментировал(а) 5 лет назад

Ok, I'll change it then. 👍

Ok, I'll change it then. :+1:
trinity-1686a одобрил(а) эти изменения 5 лет назад
trinity-1686a оставил комментарий
Владелец

👍

:+1:

Рецензенты

trinity-1686a одобрил(а) эти изменения 5 лет назад
Запрос на слияние был объединен как 80a4dae8bd.
Вы также можете просмотреть инструкции командной строки.

Шаг 1:

В репозитории вашего проекта посмотрите новую ветку и протестируйте изменения.
git checkout -b result master
git pull origin result

Шаг 2:

Объединить изменения и обновить на Forgejo.
git checkout master
git merge --no-ff result
git push origin master
Войдите, чтобы присоединиться к обсуждению.
Нет рецензентов
Нет этапа
Нет назначенных лиц
2 участников
Уведомления
Срок выполнения
Срок действия недействителен или находится за пределами допустимого диапазона. Пожалуйста, используйте формат 'гггг-мм-дд'.

Срок выполнения не установлен.

Зависимости

Зависимостей нет.

Reference: Plume/Plume#392
Загрузка…
Пока нет содержимого.