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

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 hits per line

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

71.05
/src/python/pants/option/errors.py
1
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4

5
from pants.option.scope import GLOBAL_SCOPE
3✔
6
from pants.util.strutil import pluralize, softwrap
3✔
7

8

9
class OptionsError(Exception):
3✔
10
    """An options system-related error."""
11

12

13
# -----------------------------------------------------------------------
14
# Option registration errors
15
# -----------------------------------------------------------------------
16

17

18
class RegistrationError(OptionsError):
3✔
19
    """An error at option registration time."""
20

21
    def __init__(self, scope: str, option: str, **msg_format_args) -> None:
3✔
22
        scope_str = "global scope" if scope == GLOBAL_SCOPE else f"scope {scope}"
×
23
        if self.__doc__ is None:
×
24
            raise ValueError(
×
25
                softwrap(
26
                    """
27
                    Invalid RegistrationError definition.
28
                    Please specify the error message in the docstring.
29
                    """
30
                )
31
            )
32
        docstring = self.__doc__.format(**msg_format_args)
×
33
        super().__init__(f"{docstring} [option {option} in {scope_str}].")
×
34

35

36
class BooleanOptionNameWithNo(RegistrationError):
3✔
37
    """Boolean option names cannot start with --no."""
38

39

40
class DefaultValueType(RegistrationError):
3✔
41
    """Default value {value_type}({default_value!r}) does not match option type {option_type}."""
42

43

44
class DefaultMemberValueType(DefaultValueType):
3✔
45
    """Default member value type mismatch.
46

47
    Member value {value_type}({member_value!r}) does not match list option type {member_type}.
48
    """
49

50

51
class HelpType(RegistrationError):
3✔
52
    """The `help=` argument must be a string, but was of type `{help_type}`."""
53

54

55
class InvalidKwarg(RegistrationError):
3✔
56
    """Invalid registration kwarg {kwarg}."""
57

58

59
class InvalidKwargNonGlobalScope(RegistrationError):
3✔
60
    """Invalid registration kwarg {kwarg} on non-global scope."""
61

62

63
class InvalidMemberType(RegistrationError):
3✔
64
    """member_type {member_type} not allowed."""
65

66

67
class MemberTypeNotAllowed(RegistrationError):
3✔
68
    """member_type not allowed on option with type {type_}.
69

70
    It may only be specified if type=list.
71
    """
72

73

74
class NoOptionNames(RegistrationError):
3✔
75
    """No option names provided."""
76

77

78
class OptionAlreadyRegistered(RegistrationError):
3✔
79
    """An option with this name was already registered on this scope."""
80

81

82
class OptionNameDoubleDash(RegistrationError):
3✔
83
    """Option name must begin with a double-dash."""
84

85

86
class PassthroughType(RegistrationError):
3✔
87
    """Options marked passthrough must be typed as a string list."""
88

89

90
# -----------------------------------------------------------------------
91
# Flag parsing errors
92
# -----------------------------------------------------------------------
93

94

95
class ParseError(OptionsError):
3✔
96
    """An error at flag parsing time."""
97

98

99
class BooleanConversionError(ParseError):
3✔
100
    """Indicates a value other than 'True' or 'False' when attempting to parse a bool."""
101

102

103
class FromfileError(ParseError):
3✔
104
    """Indicates a problem reading a value @fromfile."""
105

106

107
class MutuallyExclusiveOptionError(ParseError):
3✔
108
    """Indicates that two options in the same mutually exclusive group were specified."""
109

110

111
class UnknownFlagsError(ParseError):
3✔
112
    """Indicates that unknown command-line flags were encountered in some scope."""
113

114
    def __init__(self, flags: tuple[str, ...], arg_scope: str):
3✔
115
        self.flags = flags
×
116
        self.arg_scope = arg_scope
×
117
        scope = f"scope {self.arg_scope}" if self.arg_scope else "global scope"
×
118
        msg = f"Unknown {pluralize(len(self.flags), 'flag')} {', '.join(self.flags)} on {scope}"
×
119
        super().__init__(msg)
×
120

121

122
# -----------------------------------------------------------------------
123
# Config parsing errors
124
# -----------------------------------------------------------------------
125

126

127
class ConfigError(OptionsError):
3✔
128
    """An error encountered while parsing a config file."""
129

130

131
class ConfigValidationError(ConfigError):
3✔
132
    """A config file is invalid."""
133

134

135
class InterpolationMissingOptionError(ConfigError):
3✔
136
    def __init__(self, option, section, rawval, reference):
3✔
137
        super().__init__(
×
138
            self,
139
            softwrap(
140
                f"""
141
                Bad value substitution: option {option} in section {section} contains an
142
                interpolation key {reference} which is not a valid option name.
143

144
                Raw value: {rawval}
145
                """
146
            ),
147
        )
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

© 2025 Coveralls, Inc