GitoxideLabs/gitoxide · error
Colors are specific color values and their attributes, like…
Error message
Colors are specific color values and their attributes, like 'brightred', or 'blue'
What it means
`Color` values parsed from git config must be a valid color name ('red', 'brightred', 'blue', ...), an ANSI number, or a color value combined with attributes like 'bold' or 'underline'. `color_err` raises this Error with the offending input when `TryFrom<&BStr> for Color` (and the `from_str` path) fails to match any known color or attribute token.
Solutions
- Use a valid color name ('normal', 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', optionally 'bright'-prefixed) optionally followed by attributes ('bold', 'dim', 'ul', 'blink', 'reverse', 'italic', 'strike')
- Use a numeric ANSI 0-255 color instead of a made-up name
- Catch the Error and fall back to the default color setting
Example fix
// before (config)
[color]
ui = purpul bold
// after
[color]
ui = brightred bold Defensive patterns
Strategy: validation
Validate before calling
fn is_valid_git_color(s: &str) -> bool {
let colors = ["normal","black","red","green","yellow","blue","magenta","cyan","white"];
let attrs = ["bold","dim","ul","blink","reverse","italic","strike"];
let mut toks = s.split_whitespace();
let c = toks.next().unwrap_or("");
(colors.iter().any(|x| c.eq_ignore_ascii_case(x)) || c.parse::<u8>().is_ok())
&& toks.all(|t| attrs.contains(&t))
} Try / catch
let color = Color::try_from(value).unwrap_or_default();
Prevention
- Only write color names from the git-documented set
- Validate color config when accepting user input in tooling
- Fall back to defaults instead of failing on exotic color strings
When it happens
Trigger: `Color::try_from(&BStr)` or `Color::from_str` with input like 'redd', 'purplish', 'bright' alone, or an attribute spelled wrong ('bald' instead of 'bold').
Common situations: Hand-edited `[color]` sections in `.git/config`, e.g. `ui = purpul bold`, or scripts writing color values without validating against git's accepted names.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Booleans need to be 'no', 'off', 'false', '' or 'yes'…
- Integers needs to be positive or negative numbers which may…
- The remote has no URL
- Without refspecs there is nothing to show here. Add…
- (re-raised revision-spec parse error via bail!(err))
AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08).
Data as JSON: /api/errors/5244eb182a09fcea.
Report an issue: GitHub.
Appendix: source
Thrown at gix-config-value/src/color.rs:34
if write_space.take().is_some() {
write!(f, " ")?;
}
bg.fmt(f)?;
write_space = Some(());
}
if !self.attributes.is_empty() {
if write_space.take().is_some() {
write!(f, " ")?;
}
self.attributes.fmt(f)?;
}
Ok(())
}
}
fn color_err(input: impl Into<BString>) -> Error {
Error::new(
"Colors are specific color values and their attributes, like 'brightred', or 'blue'",
input,
)
}
impl TryFrom<&BStr> for Color {
type Error = Error;
fn try_from(s: &BStr) -> Result<Self, Self::Error> {
let s = std::str::from_utf8(s).map_err(|err| color_err(s).with_err(err))?;
enum ColorItem {
Value(Name),
Attr(Attribute),
}
let items = s.split_whitespace().filter_map(|s| {
if s.is_empty() {
return None;View on GitHub (pinned to e73179060b)