• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Ortham / esplugin / 14681681270

26 Apr 2025 01:25PM UTC coverage: 85.112% (-0.7%) from 85.785%
14681681270

push

github

Ortham
Deny a lot of extra lints and fix their errors

227 of 313 new or added lines in 12 files covered. (72.52%)

8 existing lines in 4 files now uncovered.

3470 of 4077 relevant lines covered (85.11%)

34.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.65
/src/error.rs
1
/*
2
 * This file is part of esplugin
3
 *
4
 * Copyright (C) 2017 Oliver Hamlet
5
 *
6
 * esplugin is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * esplugin is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with esplugin. If not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
use std::error;
21
use std::fmt;
22
use std::io;
23
use std::num::NonZeroUsize;
24
use std::path::PathBuf;
25

26
use nom::Err;
27

28
#[expect(clippy::error_impl_error)]
29
#[derive(Debug)]
30
pub enum Error {
31
    IoError(io::Error),
32
    NoFilename(PathBuf),
33
    ParsingIncomplete(MoreDataNeeded),
34
    ParsingError(Box<[u8]>, ParsingErrorKind),
35
    DecodeError(Box<[u8]>),
36
    UnresolvedRecordIds(PathBuf),
37
    PluginMetadataNotFound(String),
38
}
39

40
impl From<Err<nom::error::Error<&[u8]>>> for Error {
41
    fn from(error: Err<nom::error::Error<&[u8]>>) -> Self {
×
42
        match error {
×
43
            Err::Incomplete(nom::Needed::Unknown) => {
44
                Error::ParsingIncomplete(MoreDataNeeded::UnknownSize)
×
45
            }
46
            Err::Incomplete(nom::Needed::Size(size)) => {
×
47
                Error::ParsingIncomplete(MoreDataNeeded::Size(size))
×
48
            }
49
            Err::Error(err) | Err::Failure(err) => Error::ParsingError(
×
50
                err.input.into(),
×
NEW
51
                ParsingErrorKind::GenericParserError(err.code.description().to_owned()),
×
52
            ),
×
53
        }
54
    }
×
55
}
56

57
impl From<io::Error> for Error {
58
    fn from(error: io::Error) -> Self {
1✔
59
        Error::IoError(error)
1✔
60
    }
1✔
61
}
62

63
impl fmt::Display for Error {
64
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5✔
65
        match self {
×
66
            Error::IoError(x) => x.fmt(f),
×
NEW
67
            Error::NoFilename(path) => write!(
×
NEW
68
                f,
×
NEW
69
                "The plugin path \"{}\" has no filename part",
×
NEW
70
                path.display()
×
NEW
71
            ),
×
NEW
72
            Error::ParsingIncomplete(MoreDataNeeded::UnknownSize) => write!(
×
NEW
73
                f,
×
NEW
74
                "An unknown number of bytes of additional input was expected by the plugin parser"
×
NEW
75
            ),
×
NEW
76
            Error::ParsingIncomplete(MoreDataNeeded::Size(size)) => write!(
×
NEW
77
                f,
×
NEW
78
                "{size} bytes of additional input was expected by the plugin parser"
×
NEW
79
            ),
×
80
            Error::ParsingError(input, kind) => write!(
5✔
81
                f,
5✔
82
                "An error was encountered while parsing the plugin content \"{}\": {kind}",
5✔
83
                input.escape_ascii()
5✔
84
            ),
5✔
85
            Error::DecodeError(bytes) => write!(
×
86
                f,
×
NEW
87
                "Plugin string content could not be decoded from Windows-1252, content is \"{}\"",
×
NEW
88
                bytes.escape_ascii()
×
NEW
89
            ),
×
NEW
90
            Error::UnresolvedRecordIds(path) => write!(
×
NEW
91
                f,
×
NEW
92
                "Record IDs are unresolved for plugin at \"{}\"",
×
NEW
93
                path.display()
×
94
            ),
×
NEW
95
            Error::PluginMetadataNotFound(plugin) => {
×
NEW
96
                write!(f, "Plugin metadata for \"{plugin}\" not found")
×
97
            }
98
        }
99
    }
5✔
100
}
101

102
impl error::Error for Error {
103
    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
×
104
        match self {
×
105
            Error::IoError(x) => Some(x),
×
106
            _ => None,
×
107
        }
108
    }
×
109
}
110

111
#[derive(Debug)]
112
pub enum ParsingErrorKind {
113
    /// The `Vec<u8>` field is the expected record type.
114
    UnexpectedRecordType(Vec<u8>),
115
    /// The usize field is the expected minimum data length.
116
    SubrecordDataTooShort(usize),
117
    /// The String field is the name of the parser that errored.
118
    GenericParserError(String),
119
}
120

121
impl fmt::Display for ParsingErrorKind {
122
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5✔
123
        match self {
5✔
124
            ParsingErrorKind::UnexpectedRecordType(v) => {
4✔
125
                write!(f, "Expected record type \"{}\"", v.escape_ascii())
4✔
126
            }
127
            ParsingErrorKind::SubrecordDataTooShort(s) => write!(
1✔
128
                f,
1✔
129
                "Subrecord data field too short, expected at least {s} bytes",
1✔
130
            ),
1✔
NEW
131
            ParsingErrorKind::GenericParserError(e) => write!(f, "Error in parser: {e}"),
×
132
        }
133
    }
5✔
134
}
135

136
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
137
pub enum MoreDataNeeded {
138
    /// It's not known how much more data are needed
139
    UnknownSize,
140
    /// Contains the number of bytes of data that are needed
141
    Size(NonZeroUsize),
142
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc