reovim_kernel/core/option/
error.rs1use std::fmt;
4
5use super::{OptionScopeId, OptionValue, scope::OptionScope};
6
7#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum OptionError {
10 NotFound(String),
12
13 AlreadyExists(String),
15
16 ValidationFailed {
18 name: String,
20 reason: String,
22 },
23
24 TypeMismatch {
26 name: String,
28 expected: &'static str,
30 got: &'static str,
32 },
33
34 AliasConflict(String),
36
37 ScopeMismatch {
39 name: String,
41 option_scope: OptionScope,
43 requested: OptionScopeId,
45 },
46}
47
48impl fmt::Display for OptionError {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 match self {
51 Self::NotFound(name) => write!(f, "option not found: {name}"),
52 Self::AlreadyExists(name) => write!(f, "option already exists: {name}"),
53 Self::ValidationFailed { name, reason } => {
54 write!(f, "validation failed for '{name}': {reason}")
55 }
56 Self::TypeMismatch {
57 name,
58 expected,
59 got,
60 } => {
61 write!(f, "type mismatch for '{name}': expected {expected}, got {got}")
62 }
63 Self::AliasConflict(alias) => {
64 write!(f, "alias conflicts with existing name: {alias}")
65 }
66 Self::ScopeMismatch {
67 name,
68 option_scope,
69 requested,
70 } => {
71 write!(
72 f,
73 "scope mismatch for '{name}': option is {option_scope}, requested {requested}"
74 )
75 }
76 }
77 }
78}
79
80impl std::error::Error for OptionError {}
81
82#[derive(Debug, Clone)]
84pub struct SetResult {
85 pub old_value: Option<OptionValue>,
87 pub new_value: OptionValue,
89}