moniker/
error.rs

1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use thiserror::Error;
6
7#[cfg(feature = "serde")]
8use serde::{Deserialize, Serialize};
9
10/// Errors produced by `MonikerEnvironment`.
11#[cfg_attr(feature = "serde", derive(Deserialize, Serialize), serde(rename_all = "snake_case"))]
12#[derive(Debug, Error, Clone, PartialEq, Eq)]
13pub enum MonikerError {
14    #[error("invalid moniker: {}", rep)]
15    InvalidMoniker { rep: String },
16    #[error("invalid moniker part: {_0}")]
17    InvalidMonikerPart(#[from] cm_types::ParseError),
18    #[error("moniker {} does not have prefix {}", moniker, prefix)]
19    MonikerDoesNotHavePrefix { moniker: String, prefix: String },
20}
21
22impl MonikerError {
23    pub fn invalid_moniker(rep: impl Into<String>) -> MonikerError {
24        MonikerError::InvalidMoniker { rep: rep.into() }
25    }
26}