about summary refs log tree commit diff stats
path: root/src/error/mod.rs
blob: 0d25d90e23b65a16d2a942632db5462efe7bb290 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Back - An extremely simple git bug visualization system. Inspired by TVL's
// panettone.
//
// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de>
// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// This file is part of Back.
//
// You should have received a copy of the License along with this program.
// If not, see <https://www.gnu.org/licenses/agpl.txt>.

use std::{io, net::SocketAddr, path::PathBuf};

use git_bug::{
    entities::{identity::Identity, issue::Issue},
    replica::{
        self,
        entity::{
            id::prefix::{self, IdPrefix},
            snapshot::Snapshot,
        },
    },
};
use thiserror::Error;

pub(crate) type Result<T> = std::result::Result<T, Error>;

#[derive(Error, Debug)]
pub enum Error {
    #[error("while trying to parse the config file ({file}): {error}")]
    ConfigParse {
        file: PathBuf,
        error: serde_json::Error,
    },

    #[error("while trying to read the project.list file ({file}): {error}")]
    ProjectListRead { file: PathBuf, error: io::Error },

    #[error("while trying to read the config file ({file}): {error}")]
    ConfigRead { file: PathBuf, error: io::Error },

    #[error("Repository ('{path}') has no initialized git-bug data")]
    NotGitBug { path: PathBuf },

    #[error("while trying to open the repository ({repository_path}): {error}")]
    RepoOpen {
        repository_path: PathBuf,
        error: Box<replica::open::Error>,
    },

    #[error("while trying to get an entity reference from a replica: {0}")]
    RepoGetReferences(#[from] replica::get::Error),

    #[error("while trying to read an issues's data from a replica: {0}")]
    RepoIssueRead(#[from] replica::entity::read::Error<Issue>),

    #[error("while trying to read an identity's data from a replica: {0}")]
    RepoIdentityRead(#[from] replica::entity::read::Error<Identity>),

    #[error(
        "failed to find the repository at path: '{repository_path}' (Not registered in \
         projects.list)"
    )]
    RepoFind { repository_path: PathBuf },

    #[error("while iteration over the refs in a repository: {0}")]
    RepoRefsIter(#[from] gix::refs::packed::buffer::open::Error),

    #[error("while prefixing the refs with a path: {error}")]
    RepoRefsPrefixed { error: io::Error },

    #[error("while trying to open tcp {addr} for listening: {err}.")]
    TcpBind { addr: SocketAddr, err: io::Error },

    #[error("while trying to accept a tcp connection: {err}.")]
    TcpAccept { err: io::Error },

    #[error("There is no 'issue' associated with the prefix '{prefix}': {err}")]
    IssuesPrefixMissing {
        prefix: Box<IdPrefix>,
        err: prefix::resolve::Error,
    },

    #[error("The given prefix ('{prefix}') can not be parsed as prefix: {error}")]
    IssuesPrefixParse {
        prefix: String,
        error: prefix::decode::Error,
    },

    #[error("Route '{0}' was unknown.")]
    NotFound(PathBuf),

    #[error("Query '{query}' was not valid: {err}")]
    InvalidQuery {
        err: git_bug::query::parse::parser::Error<Snapshot<Issue>>,
        query: String,
    },
}