icu4x
icu4x copied to clipboard
Decide on names for icu_datetime and icu_calendar errors over FFI
icu_datetime and icu_calendar have many new, small error enums. We should discuss their naming conventions.
One example which isn't super great is that icu_calendar::ParseError is currently exported as CalendarParseError, even though it is the error resulting from parsing an IXDTF string to a Date, Time, or DateTime. (https://github.com/unicode-org/icu4x/pull/5260)
I want to save this discussion until after neo datetime is fully landed so that we can see exactly which error enums we're having to name in FFI.
Part of the 2.0 FFI audit
@robertbastian says he's fine with names so long as they are targeted/descriptive as opposed to reliant on the crate name.
This is blocked on https://github.com/unicode-org/icu4x/issues/5940
We don't seem to need a discussion yet, Shane plans to make a PR when ready and we can discuss if there is controversy.
Here's what we're looking at:
#[derive(Debug, PartialEq, Eq)]
#[repr(C)]
#[diplomat::rust_link(icu::calendar::RangeError, Struct, compact)]
#[diplomat::rust_link(icu::calendar::DateError, Enum, compact)]
#[cfg(any(feature = "datetime", feature = "timezone", feature = "calendar"))]
pub enum CalendarError {
Unknown = 0x00,
OutOfRange = 0x01,
UnknownEra = 0x02,
UnknownMonthCode = 0x03,
}
#[derive(Debug, PartialEq, Eq)]
#[repr(C)]
#[diplomat::rust_link(icu::calendar::ParseError, Enum, compact)]
#[diplomat::rust_link(icu::time::ParseError, Enum, compact)]
#[cfg(any(feature = "datetime", feature = "timezone", feature = "calendar"))]
pub enum CalendarParseError {
Unknown = 0x00,
InvalidSyntax = 0x01,
OutOfRange = 0x02,
MissingFields = 0x03,
UnknownCalendar = 0x04,
}
#[derive(Debug, PartialEq, Eq)]
#[diplomat::rust_link(icu::time::zone::InvalidOffsetError, Struct, compact)]
#[cfg(any(feature = "datetime", feature = "timezone"))]
pub struct TimeZoneInvalidOffsetError;
#[derive(Debug, PartialEq, Eq)]
#[repr(C)]
#[diplomat::rust_link(icu::datetime::DateTimeFormatterLoadError, Enum, compact)]
#[diplomat::rust_link(icu::datetime::pattern::PatternLoadError, Enum, compact)]
#[diplomat::rust_link(icu_provider::DataError, Struct, compact)]
#[diplomat::rust_link(icu_provider::DataErrorKind, Enum, compact)]
pub enum DateTimeFormatterLoadError {
Unknown = 0x00,
InvalidDateFields = 0x8_01,
UnsupportedLength = 0x8_03,
ConflictingField = 0x8_09,
FormatterTooSpecific = 0x8_0A,
DataMarkerNotFound = 0x01,
DataIdentifierNotFound = 0x02,
DataInvalidRequest = 0x03,
DataInconsistentData = 0x04,
DataDowncast = 0x05,
DataDeserialize = 0x06,
DataCustom = 0x07,
DataIo = 0x08,
}
#[cfg(feature = "datetime")]
#[diplomat::rust_link(icu::datetime::MismatchedCalendarError, Struct)]
pub struct DateTimeMismatchedCalendarError {
pub this_kind: CalendarKind,
pub date_kind: DiplomatOption<CalendarKind>,
}
#[cfg(feature = "datetime")]
#[derive(Debug, PartialEq, Eq)]
#[repr(C)]
#[diplomat::rust_link(
icu::datetime::unchecked::FormattedDateTimeUncheckedError,
Enum,
compact
)]
pub enum DateTimeWriteError {
Unknown = 0x00,
MissingTimeZoneId = 0x01,
MissingTimeZoneNameTimestamp = 0x02,
MissingTimeZoneVariant = 0x03,
}
DateTimeFormatterLoadError probably has more variants than are reachable. Do we care?
I don't really like the name of CalendarParseError. It applies to the parsing in both the icu_calendar and icu_time crates.
The others look plausible.
@robertbastian
Brief discussion with @robertbastian:
- Debug-assert the errors that we think are not reachable
- Rename
CalendarParseErrortoRfc9557ParseError