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

zbraniecki / icu4x / 8219362155

08 Mar 2024 01:21PM UTC coverage: 75.985% (+3.0%) from 73.009%
8219362155

push

github

web-flow
Bump diplomat (#4671)

And fix some Dart renames

49581 of 65251 relevant lines covered (75.99%)

519628.46 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;
6
use crate::fields::FieldSymbol;
7
use crate::input::CalendarError;
8
use crate::pattern::PatternError;
9
use displaydoc::Display;
10
use icu_calendar::any_calendar::AnyCalendarKind;
11
use icu_calendar::types::MonthCode;
12
use icu_decimal::DecimalError;
13
use icu_plurals::PluralsError;
14
use icu_provider::DataError;
15

16
#[cfg(feature = "std")]
17
impl std::error::Error for DateTimeError {}
18

19
/// A list of error outcomes for various operations in this module.
20
///
21
/// Re-exported as [`Error`](crate::Error).
22
#[derive(Display, Debug, Copy, Clone, PartialEq)]
×
23
#[non_exhaustive]
24
pub enum DateTimeError {
25
    /// An error originating from parsing a pattern.
26
    #[displaydoc("{0}")]
×
27
    Pattern(PatternError),
×
28
    /// An error originating from the [`Write`](std::fmt::Write) trait.
29
    #[displaydoc("{0}")]
×
30
    Format(core::fmt::Error),
×
31
    /// An error originating inside of the [data provider](icu_provider).
32
    #[displaydoc("{0}")]
×
33
    Data(DataError),
×
34
    /// An error originating from a missing field in datetime input.
35
    /// TODO: How can we return which field was missing?
36
    #[displaydoc("Missing input field")]
37
    MissingInputField(Option<&'static str>),
×
38
    /// An error originating from skeleton matching.
39
    #[displaydoc("{0}")]
×
40
    #[cfg(feature = "experimental")]
41
    Skeleton(crate::skeleton::SkeletonError),
×
42
    /// An error originating from an unsupported field in a datetime format.
43
    #[displaydoc("Unsupported field: {0:?}")]
44
    UnsupportedField(FieldSymbol),
×
45
    /// An unsupported field with a field length.
46
    // TODO(#2856): Consider renaming `UnsupportedField` to `UnsupportedFieldSymbol` so that
47
    // this variant can be named `UnsupportedField`.
48
    #[displaydoc("Unsupported field: {0:?}")]
49
    UnsupportedFormattingField(Field),
×
50
    /// An error due to there being no patterns for the given options.
51
    #[displaydoc("Unsupported options")]
52
    UnsupportedOptions,
53
    /// An error originating from [`PluralRules`][icu_plurals::PluralRules].
54
    #[displaydoc("{0}")]
×
55
    PluralRules(PluralsError),
×
56
    /// An error originating from [`DateTimeInput`][crate::input::DateTimeInput].
57
    #[displaydoc("{0}")]
×
58
    DateTimeInput(CalendarError),
×
59
    /// An error originating from a missing weekday symbol in the data.
60
    #[displaydoc("Data file missing weekday symbol for weekday {0}")]
×
61
    MissingWeekdaySymbol(usize),
×
62
    /// An error originating from a missing month symbol in the data.
63
    #[displaydoc("Data file missing month symbol for month code {0}")]
×
64
    MissingMonthSymbol(MonthCode),
×
65
    /// An error while attempting to format the input as a FixedDecimal
66
    #[displaydoc("FixedDecimal")]
67
    FixedDecimal,
68
    /// An error originating from FixedDecimalFormatter
69
    #[displaydoc("{0}")]
×
70
    FixedDecimalFormatter(DecimalError),
×
71
    /// An error from mixing calendar types in [`DateTimeFormatter`](crate::DateTimeFormatter)
72
    #[displaydoc("DateTimeFormatter for {0} calendar was given a {1:?} calendar")]
×
73
    MismatchedAnyCalendar(AnyCalendarKind, Option<AnyCalendarKind>),
×
74
    /// Missing date symbols
75
    #[displaydoc("Missing date symbols")]
76
    MissingDateSymbols,
77
    /// Missing time symbols
78
    #[displaydoc("Missing time symbols")]
79
    MissingTimeSymbols,
80
    /// ordinal_rules must be set for PatternPlurals::MultipleVariants
81
    #[displaydoc("ordinal_rules must be set for PatternPlurals::MultipleVariants")]
82
    MissingOrdinalRules,
83
    /// The names for the given field are not loaded
84
    #[displaydoc("Missing names for {0:?}")]
85
    MissingNames(Field),
×
86
    /// The same field occurs multiple times in a pattern or was loaded multiple times
87
    #[displaydoc("Duplicate field: {0:?}")]
88
    DuplicateField(Field),
×
89
}
90

91
/// An error from mixing calendar types in [`DateTimeFormatter`](crate::DateTimeFormatter)
92
#[derive(Display, Debug, Copy, Clone, PartialEq)]
×
93
#[displaydoc("DateTimeFormatter for {this_kind} calendar was given a {date_kind:?} calendar")]
×
94
#[non_exhaustive]
95
pub struct MismatchedCalendarError {
96
    /// The calendar kind of the target object (formatter).
97
    pub this_kind: AnyCalendarKind,
×
98
    /// The calendar kind of the input object (date being formatted).
99
    /// Can be `None` if the input calendar was not specified.
100
    pub date_kind: Option<AnyCalendarKind>,
×
101
}
102

103
impl From<PatternError> for DateTimeError {
104
    fn from(e: PatternError) -> Self {
×
105
        DateTimeError::Pattern(e)
×
106
    }
×
107
}
108

109
impl From<DataError> for DateTimeError {
110
    fn from(e: DataError) -> Self {
×
111
        DateTimeError::Data(e)
×
112
    }
×
113
}
114

115
impl From<core::fmt::Error> for DateTimeError {
116
    fn from(e: core::fmt::Error) -> Self {
×
117
        DateTimeError::Format(e)
×
118
    }
×
119
}
120

121
impl From<PluralsError> for DateTimeError {
122
    fn from(e: PluralsError) -> Self {
×
123
        DateTimeError::PluralRules(e)
×
124
    }
×
125
}
126

127
impl From<CalendarError> for DateTimeError {
128
    fn from(e: CalendarError) -> Self {
×
129
        DateTimeError::DateTimeInput(e)
×
130
    }
×
131
}
132

133
impl From<DecimalError> for DateTimeError {
134
    fn from(e: DecimalError) -> Self {
×
135
        DateTimeError::FixedDecimalFormatter(e)
×
136
    }
×
137
}
138

139
impl From<MismatchedCalendarError> for DateTimeError {
140
    fn from(e: MismatchedCalendarError) -> Self {
×
141
        DateTimeError::MismatchedAnyCalendar(e.this_kind, e.date_kind)
×
142
    }
×
143
}
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