actix / actix-extras

Compare fc6563a ... +5 ... d0f0fb4

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -0,0 +1,66 @@
Loading
1 +
use std::{error::Error as StdError, fmt};
2 +
3 +
use actix_web::ResponseError;
4 +
use derive_more::Display;
5 +
6 +
#[derive(Debug, Display)]
7 +
pub(crate) enum InsertErrorKind {
8 +
    #[display(fmt = "{}", _0)]
9 +
    Json(serde_json::Error),
10 +
}
11 +
12 +
impl Into<actix_web::Error> for InsertErrorKind {
13 +
    fn into(self) -> actix_web::Error {
14 +
        match self {
15 +
            InsertErrorKind::Json(err) => err.into(),
16 +
        }
17 +
    }
18 +
}
19 +
20 +
/// Error returned by [`Session::insert`][crate::Session::insert]. Allows access to value that
21 +
/// failed to be inserted.
22 +
pub struct InsertError<T> {
23 +
    pub(crate) value: Option<T>,
24 +
    pub(crate) error: InsertErrorKind,
25 +
}
26 +
27 +
impl<T> InsertError<T> {
28 +
    /// Takes value out of error.
29 +
    ///
30 +
    /// # Panics
31 +
    /// Panics if called more than once.
32 +
    pub fn take_value(&mut self) -> T {
33 +
        self.value
34 +
            .take()
35 +
            .expect("take_value should only be called once")
36 +
    }
37 +
}
38 +
39 +
impl<T> fmt::Debug for InsertError<T> {
40 +
    fn fmt<'a>(&'a self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 +
        let mut dbg = f.debug_struct("SessionInsertError");
42 +
43 +
        match &self.value {
44 +
            Some(_) => dbg.field("value", &"Some([value])" as _),
45 +
            None => dbg.field("value", &None::<()> as _),
46 +
        };
47 +
48 +
        dbg.field("error", &self.error).finish()
49 +
    }
50 +
}
51 +
52 +
impl<T> fmt::Display for InsertError<T> {
53 +
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 +
        fmt::Display::fmt(&self.error, f)
55 +
    }
56 +
}
57 +
58 +
impl<T: fmt::Debug> StdError for InsertError<T> {
59 +
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
60 +
        Some(match &self.error {
61 +
            InsertErrorKind::Json(err) => err,
62 +
        })
63 +
    }
64 +
}
65 +
66 +
impl<T> ResponseError for InsertError<T> {}

@@ -382,7 +382,7 @@
Loading
382 382
    use super::*;
383 383
    use actix_session::Session;
384 384
    use actix_web::{
385 -
        middleware, test, web,
385 +
        middleware, web,
386 386
        web::{get, post, resource},
387 387
        App, HttpResponse, Result,
388 388
    };
@@ -483,7 +483,7 @@
Loading
483 483
        //   - set-cookie actix-session will be in response (session cookie #3)
484 484
        //   - response should be: {"counter": 0, "user_id": None}
485 485
486 -
        let srv = test::start(|| {
486 +
        let srv = actix_test::start(|| {
487 487
            App::new()
488 488
                .wrap(
489 489
                    RedisSession::new("127.0.0.1:6379", &[0; 32])
@@ -680,7 +680,7 @@
Loading
680 680
        //
681 681
        // Test that removing max_age results in a session-only cookie
682 682
        //
683 -
        let srv = test::start(|| {
683 +
        let srv = actix_test::start(|| {
684 684
            App::new()
685 685
                .wrap(
686 686
                    RedisSession::new("127.0.0.1:6379", &[0; 32])

Learn more Showing 1 files with coverage changes found.

New file actix-session/src/_error.rs
New
Loading file...
Files Coverage
actix-cors/src 87.59%
actix-identity/src 95.96%
actix-redis/src 82.10%
actix-session/src -4.24% 83.73%
actix-web-httpauth/src 60.59%
actix-protobuf/src/lib.rs 50.00%
Project Totals (30 files) 79.82%
Loading