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

zbraniecki / icu4x / 12020603084

23 Nov 2024 08:43PM UTC coverage: 75.71% (+0.2%) from 75.477%
12020603084

push

github

sffc
Touch Cargo.lock

55589 of 73424 relevant lines covered (75.71%)

644270.14 hits per line

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

0.0
/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::{fields::Field, 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::TypedDateTimeNames;
15
#[cfg(doc)]
16
use icu_calendar::types::YearInfo;
17
#[cfg(doc)]
18
use icu_decimal::FixedDecimalFormatter;
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
/// An error from mixing calendar types in a formatter.
34
#[derive(Display, Debug, Copy, Clone, PartialEq)]
×
35
#[displaydoc("DateTimeFormatter for {this_kind} calendar was given a {date_kind:?} calendar")]
×
36
#[non_exhaustive]
37
pub struct MismatchedCalendarError {
38
    /// The calendar kind of the target object (formatter).
39
    pub this_kind: AnyCalendarKind,
×
40
    /// The calendar kind of the input object (date being formatted).
41
    /// Can be `None` if the input calendar was not specified.
42
    pub date_kind: Option<AnyCalendarKind>,
×
43
}
44

45
#[non_exhaustive]
46
#[derive(Debug, PartialEq, Copy, Clone, displaydoc::Display)]
×
47
/// Error for `TryWriteable` implementations
48
pub enum DateTimeWriteError {
49
    /// The [`MonthCode`] of the input is not valid for this calendar.
50
    ///
51
    /// This is guaranteed not to happen for `icu::calendar` inputs, but may happen for custom inputs.
52
    ///
53
    /// The output will contain the raw [`MonthCode`] as a fallback value.
54
    #[displaydoc("Invalid month {0:?}")]
55
    InvalidMonthCode(MonthCode),
×
56
    /// The [`FormattingEra`] of the input is not valid for this calendar.
57
    ///
58
    /// This is guaranteed not to happen for `icu::calendar` inputs, but may happen for custom inputs.
59
    ///
60
    /// The output will contain [`FormattingEra::fallback_name`] as the fallback.
61
    #[displaydoc("Invalid era {0:?}")]
62
    InvalidEra(FormattingEra),
×
63
    /// The [`YearInfo::cyclic`] 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 [`YearInfo::extended_year`] as a fallback value.
68
    #[displaydoc("Invalid cyclic year {value} (maximum {max})")]
×
69
    InvalidCyclicYear {
70
        /// Value
71
        value: usize,
×
72
        /// Max
73
        max: usize,
×
74
    },
75

76
    /// The [`FixedDecimalFormatter`] has not been loaded.
77
    ///
78
    /// This *only* happens if the formatter has been created using
79
    /// [`TypedDateTimeNames::with_pattern_unchecked`], the pattern requires decimal
80
    /// formatting, and the decimal formatter was not loaded.
81
    ///
82
    /// The output will contain fallback values using Latin numerals.
83
    #[displaydoc("FixedDecimalFormatter not loaded")]
84
    FixedDecimalFormatterNotLoaded,
85
    /// The localized names for a field have not been loaded.
86
    ///
87
    /// This *only* happens if the formatter has been created using
88
    /// [`TypedDateTimeNames::with_pattern_unchecked`], and the pattern requires names
89
    /// that were not loaded.
90
    ///
91
    /// The output will contain fallback values using field identifiers (such as `tue` for `IsoWeekday::Tuesday`,
92
    /// `M02` for month 2, etc.).
93
    #[displaydoc("Names for {0:?} not loaded")]
94
    NamesNotLoaded(Field),
×
95
    /// An input field (such as "hour" or "month") is missing.
96
    ///
97
    /// This *only* happens if the formatter has been created using
98
    /// [`TypedDateTimeNames::with_pattern_unchecked`], and the pattern requires fields
99
    /// that are not returned by the input type.
100
    ///
101
    /// The output will contain the string `{X}` instead, where `X` is the symbol for which the input is missing.
102
    #[displaydoc("Incomplete input, missing value for {0:?}")]
103
    MissingInputField(&'static str),
×
104
    /// Unsupported field
105
    ///
106
    /// This *only* happens if the formatter has been created using
107
    /// [`TypedDateTimeNames::with_pattern_unchecked`], and the pattern contains unsupported fields.
108
    ///
109
    /// The output will contain the string `{unsupported:X}`, where `X` is the symbol of the unsupported field.
110
    #[displaydoc("Unsupported field {0:?}")]
111
    UnsupportedField(Field),
×
112
}
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