• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zbraniecki / icu4x / 13958601093

19 Mar 2025 04:17PM UTC coverage: 74.164% (-1.5%) from 75.71%
13958601093

push

github

web-flow
Clean up properties docs (#6315)

58056 of 78281 relevant lines covered (74.16%)

819371.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

8.33
/components/datetime/src/error.rs
1
// This file is part of ICU4X. For terms of use, please see the file
2
// called LICENSE at the top level of the ICU4X source tree
3
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4

5
use crate::pattern::PatternLoadError;
6
use displaydoc::Display;
7
use icu_calendar::{
8
    any_calendar::AnyCalendarKind,
9
    types::{FormattingEra, MonthCode},
10
};
11
use icu_provider::DataError;
12

13
#[cfg(doc)]
14
use crate::pattern::FixedCalendarDateTimeNames;
15
#[cfg(doc)]
16
use icu_calendar::types::YearInfo;
17
#[cfg(doc)]
18
use icu_decimal::DecimalFormatter;
19

20
/// An error from constructing a formatter.
21
#[derive(Display, Debug, Copy, Clone, PartialEq)]
×
22
#[non_exhaustive]
23
pub enum DateTimeFormatterLoadError {
24
    /// An error while loading display names for a field.
25
    #[displaydoc("{0}")]
×
26
    Names(PatternLoadError),
×
27
    /// An error while loading some other required data,
28
    /// such as skeleton patterns or calendar conversions.
29
    #[displaydoc("{0}")]
×
30
    Data(DataError),
×
31
}
32

33
impl core::error::Error for DateTimeFormatterLoadError {}
34

35
impl From<DataError> for DateTimeFormatterLoadError {
36
    fn from(error: DataError) -> Self {
×
37
        Self::Data(error)
×
38
    }
×
39
}
40

41
/// The specific field for which an error occurred.
42
#[derive(Display, Debug, Copy, Clone, PartialEq)]
4✔
43
pub struct ErrorField(pub(crate) crate::provider::fields::Field);
2✔
44

45
/// An error from mixing calendar types in a formatter.
46
#[derive(Display, Debug, Copy, Clone, PartialEq)]
×
47
#[displaydoc("DateTimeFormatter for {this_kind} calendar was given a {date_kind:?} calendar")]
×
48
#[non_exhaustive]
49
pub struct MismatchedCalendarError {
50
    /// The calendar kind of the target object (formatter).
51
    pub this_kind: AnyCalendarKind,
×
52
    /// The calendar kind of the input object (date being formatted).
53
    /// Can be `None` if the input calendar was not specified.
54
    pub date_kind: Option<AnyCalendarKind>,
×
55
}
56

57
impl core::error::Error for MismatchedCalendarError {}
58

59
#[non_exhaustive]
60
#[derive(Debug, PartialEq, Copy, Clone, displaydoc::Display)]
×
61
/// Error for `TryWriteable` implementations
62
pub enum DateTimeWriteError {
63
    /// The [`MonthCode`] of the input is not valid for this calendar.
64
    ///
65
    /// This is guaranteed not to happen for `icu::calendar` inputs, but may happen for custom inputs.
66
    ///
67
    /// The output will contain the raw [`MonthCode`] as a fallback value.
68
    #[displaydoc("Invalid month {0:?}")]
69
    InvalidMonthCode(MonthCode),
×
70
    /// The [`FormattingEra`] of the input is not valid for this calendar.
71
    ///
72
    /// This is guaranteed not to happen for `icu::calendar` inputs, but may happen for custom inputs.
73
    ///
74
    /// The output will contain [`FormattingEra::fallback_name`] as the fallback.
75
    #[displaydoc("Invalid era {0:?}")]
76
    InvalidEra(FormattingEra),
×
77
    /// The [`YearInfo::cyclic`] of the input is not valid for this calendar.
78
    ///
79
    /// This is guaranteed not to happen for `icu::calendar` inputs, but may happen for custom inputs.
80
    ///
81
    /// The output will contain [`YearInfo::extended_year`] as a fallback value.
82
    #[displaydoc("Invalid cyclic year {value} (maximum {max})")]
×
83
    InvalidCyclicYear {
84
        /// Value
85
        value: usize,
×
86
        /// Max
87
        max: usize,
×
88
    },
89

90
    /// The [`DecimalFormatter`] has not been loaded.
91
    ///
92
    /// This *only* happens if the formatter has been created using
93
    /// [`FixedCalendarDateTimeNames::with_pattern_unchecked`], the pattern requires decimal
94
    /// formatting, and the decimal formatter was not loaded.
95
    ///
96
    /// The output will contain fallback values using Latin numerals.
97
    #[displaydoc("DecimalFormatter not loaded")]
98
    DecimalFormatterNotLoaded,
99
    /// The localized names for a field have not been loaded.
100
    ///
101
    /// This *only* happens if the formatter has been created using
102
    /// [`FixedCalendarDateTimeNames::with_pattern_unchecked`], and the pattern requires names
103
    /// that were not loaded.
104
    ///
105
    /// The output will contain fallback values using field identifiers (such as `tue` for `Weekday::Tuesday`,
106
    /// `M02` for month 2, etc.).
107
    #[displaydoc("Names for {0:?} not loaded")]
108
    NamesNotLoaded(ErrorField),
×
109
    /// An input field (such as "hour" or "month") is missing.
110
    ///
111
    /// This *only* happens if the formatter has been created using
112
    /// [`FixedCalendarDateTimeNames::with_pattern_unchecked`], and the pattern requires fields
113
    /// that are not returned by the input type.
114
    ///
115
    /// The output will contain the string `{X}` instead, where `X` is the symbol for which the input is missing.
116
    #[displaydoc("Incomplete input, missing value for {0:?}")]
117
    MissingInputField(&'static str),
×
118
    /// The pattern contains a field that has a valid symbol but invalid length.
119
    ///
120
    /// This *only* happens if the formatter has been created using
121
    /// [`FixedCalendarDateTimeNames::with_pattern_unchecked`], and the pattern contains
122
    /// a field with a length not supported in formatting.
123
    ///
124
    /// The output will contain fallback values similar to [`DateTimeWriteError::NamesNotLoaded`].
125
    #[displaydoc("Field length for {0:?} is invalid")]
126
    UnsupportedLength(ErrorField),
×
127
    /// Unsupported field
128
    ///
129
    /// This *only* happens if the formatter has been created using
130
    /// [`FixedCalendarDateTimeNames::with_pattern_unchecked`], and the pattern contains unsupported fields.
131
    ///
132
    /// The output will contain the string `{unsupported:X}`, where `X` is the symbol of the unsupported field.
133
    #[displaydoc("Unsupported field {0:?}")]
134
    UnsupportedField(ErrorField),
×
135
}
136

137
impl core::error::Error for DateTimeWriteError {}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc