ltk/theme/
error.rs

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
// SPDX-License-Identifier: LGPL-2.1-only
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>

//! Error type returned by theme loading and parsing.

use std::fmt;
use std::io;
use std::path::PathBuf;

#[ derive( Debug ) ]
pub enum ThemeError
{
	Io( PathBuf, io::Error ),
	ParseJson( PathBuf, serde_json::Error ),
	NotFound( String ),
	InvalidColor( String ),
	UnknownColorRef( String ),
}

impl fmt::Display for ThemeError
{
	fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
	{
		match self
		{
			ThemeError::Io( p, e )            => write!( f, "reading {}: {}", p.display(), e ),
			ThemeError::ParseJson( p, e )     => write!( f, "parsing {}: {}", p.display(), e ),
			ThemeError::NotFound( id )        => write!( f, "theme `{}` not found in any search path", id ),
			ThemeError::InvalidColor( s )     => write!( f, "invalid colour `{}` (expected #RRGGBB, #RRGGBBAA or rgb[a](…))", s ),
			ThemeError::UnknownColorRef( s )  => write!( f, "unknown reference `@{}` (not defined in top-level `colors`, `gradients` or `inset_stacks`)", s ),
		}
	}
}

impl std::error::Error for ThemeError {}