Skip to main content

aj_models/
errors.rs

1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4#[derive(Error, Debug, Serialize, Deserialize)]
5#[serde(rename_all = "snake_case")]
6pub enum AdaJudgeError {
7    #[error("not found")]
8    NotFound,
9
10    #[error("internal error")]
11    Internal,
12
13    #[error("invalid problem config")]
14    InvalidProblem(#[from] InvalidProblem),
15
16    #[error("invalid JWT")]
17    InvalidJwt,
18
19    #[error("auth error")]
20    Auth(#[from] AuthError),
21
22    #[error("deletion error")]
23    Deletion(#[from] Deletion),
24
25    #[error("forbidden")]
26    Forbidden,
27
28    #[error("contest error")]
29    Contest(#[from] Contest),
30
31    #[error("bad request")]
32    BadRequest,
33}
34
35#[derive(Error, Debug, Serialize, Deserialize)]
36#[serde(tag = "kind", rename_all = "snake_case")]
37pub enum AuthError {
38    #[error("invalid login or password")]
39    InvalidLoginOrPassword,
40
41    #[error("user already exists")]
42    AlreadyExists,
43
44    #[error("passwords don't match")]
45    PasswordsDontMatch,
46}
47
48#[derive(Error, Debug, Serialize, Deserialize)]
49#[serde(tag = "kind", rename_all = "snake_case")]
50pub enum InvalidProblem {
51    #[error("subgroup {subgroup} depends on subgroup {depends_on}")]
52    SubgroupConflict { subgroup: usize, depends_on: usize },
53
54    #[error("subgroup {subgroup} has both score and score_per_test fields (or no of them)")]
55    InvalidSubgroupScoring { subgroup: usize },
56
57    #[error("no problem config found")]
58    MissingConfig,
59
60    #[error("toml error")]
61    TomlError { message: String },
62
63    #[error("owner id doesn't match or missing")]
64    OwnerId,
65}
66
67#[derive(Error, Debug, Serialize, Deserialize)]
68#[serde(tag = "kind", rename_all = "snake_case")]
69pub enum Deletion {
70    #[error("invalid login or password")]
71    InvalidLoginOrPassword,
72
73    #[error("missing deletion confirmation")]
74    MissingDeletionConfirmation,
75}
76
77#[derive(Error, Debug, Serialize, Deserialize)]
78#[serde(tag = "kind", rename_all = "snake_case")]
79pub enum Contest {
80    #[error("start time is >= finish time")]
81    Time,
82}