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
36
37
38
39
40
41
42
43
// 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;

/// What went wrong while locating, reading or parsing a theme.
#[ derive( Debug ) ]
pub enum ThemeError
{
	/// An I/O error reading the theme file at the given path.
	Io( PathBuf, io::Error ),
	/// The theme file at the given path was not valid JSON.
	ParseJson( PathBuf, serde_json::Error ),
	/// No theme with this id was found in any search path.
	NotFound( String ),
	/// A colour literal was not a recognised form (`#RRGGBB`, `#RRGGBBAA` or
	/// `rgb[a](…)`).
	InvalidColor( String ),
	/// A `@name` reference was not defined in the top-level `colors`,
	/// `gradients` or `inset_stacks`.
	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 {}