Skip to content

Commit

Permalink
errs
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Feb 28, 2024
1 parent 59a8e63 commit d769844
Show file tree
Hide file tree
Showing 69 changed files with 304 additions and 985 deletions.
10 changes: 5 additions & 5 deletions components/calendar/src/any_calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ impl AnyCalendar {
pub fn try_new_with_any_provider<P>(
provider: &P,
kind: AnyCalendarKind,
) -> Result<Self, CalendarError>
) -> Result<Self, DataError>
where
P: AnyProvider + ?Sized,
{
Expand Down Expand Up @@ -650,7 +650,7 @@ impl AnyCalendar {
pub fn try_new_with_buffer_provider<P>(
provider: &P,
kind: AnyCalendarKind,
) -> Result<Self, CalendarError>
) -> Result<Self, DataError>
where
P: BufferProvider + ?Sized,
{
Expand Down Expand Up @@ -691,7 +691,7 @@ impl AnyCalendar {
}

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<P>(provider: &P, kind: AnyCalendarKind) -> Result<Self, CalendarError>
pub fn try_new_unstable<P>(provider: &P, kind: AnyCalendarKind) -> Result<Self, DataError>
where
P: DataProvider<crate::provider::JapaneseErasV1Marker>
+ DataProvider<crate::provider::JapaneseExtendedErasV1Marker>
Expand Down Expand Up @@ -748,7 +748,7 @@ impl AnyCalendar {
icu_provider::gen_any_buffer_data_constructors!(
locale: include,
options: skip,
error: CalendarError,
error: DataError,
#[cfg(skip)]
functions: [
new_for_locale,
Expand All @@ -763,7 +763,7 @@ impl AnyCalendar {
pub fn try_new_for_locale_unstable<P>(
provider: &P,
locale: &DataLocale,
) -> Result<Self, CalendarError>
) -> Result<Self, DataError>
where
P: DataProvider<crate::provider::JapaneseErasV1Marker>
+ DataProvider<crate::provider::JapaneseExtendedErasV1Marker>
Expand Down
4 changes: 2 additions & 2 deletions components/calendar/src/chinese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl Chinese {
}
}

icu_provider::gen_any_buffer_data_constructors!(locale: skip, options: skip, error: CalendarError,
icu_provider::gen_any_buffer_data_constructors!(locale: skip, options: skip, error: DataError,
#[cfg(skip)]
functions: [
new,
Expand All @@ -172,7 +172,7 @@ impl Chinese {
#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<D: DataProvider<ChineseCacheV1Marker> + ?Sized>(
provider: &D,
) -> Result<Self, CalendarError> {
) -> Result<Self, DataError> {
Ok(Self {
data: Some(provider.load(Default::default())?.take_payload()?),
})
Expand Down
4 changes: 2 additions & 2 deletions components/calendar/src/dangi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Dangi {
}
}

icu_provider::gen_any_buffer_data_constructors!(locale: skip, options: skip, error: CalendarError,
icu_provider::gen_any_buffer_data_constructors!(locale: skip, options: skip, error: DataError,
#[cfg(skip)]
functions: [
new,
Expand All @@ -164,7 +164,7 @@ impl Dangi {
#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<D: DataProvider<DangiCacheV1Marker> + ?Sized>(
provider: &D,
) -> Result<Self, CalendarError> {
) -> Result<Self, DataError> {
Ok(Self {
data: Some(provider.load(Default::default())?.take_payload()?),
})
Expand Down
13 changes: 3 additions & 10 deletions components/calendar/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use displaydoc::Display;
use icu_provider::DataError;
use tinystr::{tinystr, TinyStr16, TinyStr4};
use writeable::Writeable;

Expand Down Expand Up @@ -53,9 +52,9 @@ pub enum CalendarError {
/// An operation required a calendar but a calendar was not provided.
#[displaydoc("An operation required a calendar but a calendar was not provided")]
MissingCalendar,
/// An error originating inside of the [data provider](icu_provider).
#[displaydoc("{0}")]
Data(DataError),
// /// An error originating inside of the [data provider](icu_provider).
// #[displaydoc("{0}")]
// Data(DataError),
}

impl From<core::num::ParseIntError> for CalendarError {
Expand All @@ -64,12 +63,6 @@ impl From<core::num::ParseIntError> for CalendarError {
}
}

impl From<DataError> for CalendarError {
fn from(e: DataError) -> Self {
CalendarError::Data(e)
}
}

impl CalendarError {
/// Create an error when an [`AnyCalendarKind`] is expected but not available.
///
Expand Down
8 changes: 4 additions & 4 deletions components/calendar/src/japanese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Japanese {
}
}

icu_provider::gen_any_buffer_data_constructors!(locale: skip, options: skip, error: CalendarError,
icu_provider::gen_any_buffer_data_constructors!(locale: skip, options: skip, error: DataError,
#[cfg(skip)]
functions: [
new,
Expand All @@ -141,7 +141,7 @@ impl Japanese {
#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<D: DataProvider<JapaneseErasV1Marker> + ?Sized>(
provider: &D,
) -> Result<Self, CalendarError> {
) -> Result<Self, DataError> {
Ok(Self {
eras: provider.load(Default::default())?.take_payload()?,
})
Expand Down Expand Up @@ -187,7 +187,7 @@ impl JapaneseExtended {
})
}

icu_provider::gen_any_buffer_data_constructors!(locale: skip, options: skip, error: CalendarError,
icu_provider::gen_any_buffer_data_constructors!(locale: skip, options: skip, error: DataError,
#[cfg(skip)]
functions: [
new,
Expand All @@ -200,7 +200,7 @@ impl JapaneseExtended {
#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<D: DataProvider<JapaneseExtendedErasV1Marker> + ?Sized>(
provider: &D,
) -> Result<Self, CalendarError> {
) -> Result<Self, DataError> {
Ok(Self(Japanese {
eras: provider.load(Default::default())?.take_payload()?.cast(),
}))
Expand Down
8 changes: 4 additions & 4 deletions components/calendar/src/week_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ impl WeekCalculator {
///
/// [📚 Help choosing a constructor](icu_provider::constructors)
#[cfg(feature = "compiled_data")]
pub fn try_new(locale: &DataLocale) -> Result<Self, CalendarError> {
pub fn try_new(locale: &DataLocale) -> Result<Self, DataError> {
Self::try_new_unstable(&crate::provider::Baked, locale)
}

#[doc = icu_provider::gen_any_buffer_unstable_docs!(ANY, Self::try_new_unstable)]
pub fn try_new_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
locale: &DataLocale,
) -> Result<Self, CalendarError> {
) -> Result<Self, DataError> {
Self::try_new_unstable(&provider.as_downcasting(), locale).or_else(|e| {
DataProvider::<WeekDataV1Marker>::load(
&provider.as_downcasting(),
Expand All @@ -80,7 +80,7 @@ impl WeekCalculator {
pub fn try_new_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
locale: &DataLocale,
) -> Result<Self, CalendarError> {
) -> Result<Self, DataError> {
Self::try_new_unstable(&provider.as_deserializing(), locale).or_else(|e| {
DataProvider::<WeekDataV1Marker>::load(
&provider.as_deserializing(),
Expand All @@ -96,7 +96,7 @@ impl WeekCalculator {
}

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
pub fn try_new_unstable<P>(provider: &P, locale: &DataLocale) -> Result<Self, CalendarError>
pub fn try_new_unstable<P>(provider: &P, locale: &DataLocale) -> Result<Self, DataError>
where
P: DataProvider<crate::provider::WeekDataV2Marker> + ?Sized,
{
Expand Down
16 changes: 3 additions & 13 deletions components/casemap/src/titlecase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use alloc::string::String;
use icu_locid::LanguageIdentifier;
use icu_properties::maps::CodePointMapData;
use icu_properties::provider::GeneralCategoryV1Marker;
use icu_properties::{GeneralCategory, GeneralCategoryGroup, PropertiesError};
use icu_properties::{GeneralCategory, GeneralCategoryGroup};
use icu_provider::prelude::*;
use writeable::Writeable;

Expand Down Expand Up @@ -234,12 +234,7 @@ impl TitlecaseMapper<CaseMapper> {
P: DataProvider<CaseMapV1Marker> + DataProvider<GeneralCategoryV1Marker> + ?Sized,
{
let cm = CaseMapper::try_new_unstable(provider)?;
let gc = icu_properties::maps::load_general_category(provider).map_err(|e| {
let PropertiesError::PropDataLoad(e) = e else {
unreachable!()
};
e
})?;
let gc = icu_properties::maps::load_general_category(provider)?;
Ok(Self { cm, gc })
}
}
Expand Down Expand Up @@ -276,12 +271,7 @@ impl<CM: AsRef<CaseMapper>> TitlecaseMapper<CM> {
where
P: DataProvider<CaseMapV1Marker> + DataProvider<GeneralCategoryV1Marker> + ?Sized,
{
let gc = icu_properties::maps::load_general_category(provider).map_err(|e| {
let PropertiesError::PropDataLoad(e) = e else {
unreachable!()
};
e
})?;
let gc = icu_properties::maps::load_general_category(provider)?;
Ok(Self { cm: casemapper, gc })
}

Expand Down
21 changes: 11 additions & 10 deletions components/collator/src/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::elements::{
CollationElement, CollationElements, NonPrimary, JAMO_COUNT, NO_CE, NO_CE_PRIMARY,
NO_CE_SECONDARY, NO_CE_TERTIARY, OPTIMIZED_DIACRITICS_MAX_COUNT, QUATERNARY_MASK,
};
use crate::error::CollatorError;
use crate::options::CollatorOptionsBitField;
use crate::provider::CollationDataV1Marker;
use crate::provider::CollationDiacriticsV1Marker;
Expand Down Expand Up @@ -70,7 +69,7 @@ pub struct Collator {
impl Collator {
/// Creates a collator for the given locale and options from compiled data.
#[cfg(feature = "compiled_data")]
pub fn try_new(locale: &DataLocale, options: CollatorOptions) -> Result<Self, CollatorError> {
pub fn try_new(locale: &DataLocale, options: CollatorOptions) -> Result<Self, DataError> {
Self::try_new_unstable_internal(
&crate::provider::Baked,
DataPayload::from_static_ref(
Expand All @@ -93,7 +92,7 @@ impl Collator {
icu_provider::gen_any_buffer_data_constructors!(
locale: include,
options: CollatorOptions,
error: CollatorError,
error: DataError,
#[cfg(skip)]
);

Expand All @@ -102,7 +101,7 @@ impl Collator {
provider: &D,
locale: &DataLocale,
options: CollatorOptions,
) -> Result<Self, CollatorError>
) -> Result<Self, DataError>
where
D: DataProvider<CollationSpecialPrimariesV1Marker>
+ DataProvider<CollationDataV1Marker>
Expand Down Expand Up @@ -136,7 +135,7 @@ impl Collator {
>,
locale: &DataLocale,
options: CollatorOptions,
) -> Result<Self, CollatorError>
) -> Result<Self, DataError>
where
D: DataProvider<CollationDataV1Marker>
+ DataProvider<CollationDiacriticsV1Marker>
Expand Down Expand Up @@ -170,7 +169,7 @@ impl Collator {

if let Some(reordering) = &reordering {
if reordering.get().reorder_table.len() != 256 {
return Err(CollatorError::MalformedData);
return Err(DataError::custom("invalid").with_key(CollationReorderingV1Marker::KEY));
}
}

Expand All @@ -193,15 +192,15 @@ impl Collator {
// Vietnamese and Ewe load a full-length alternative table and the rest use
// the default one.
if diacritics.get().secondaries.len() > OPTIMIZED_DIACRITICS_MAX_COUNT {
return Err(CollatorError::MalformedData);
return Err(DataError::custom("invalid").with_key(CollationDiacriticsV1Marker::KEY));
}
} else if diacritics.get().secondaries.len() != OPTIMIZED_DIACRITICS_MAX_COUNT {
return Err(CollatorError::MalformedData);
return Err(DataError::custom("invalid").with_key(CollationDiacriticsV1Marker::KEY));
}

// TODO: redesign Korean search collation handling
if jamo.get().ce32s.len() != JAMO_COUNT {
return Err(CollatorError::MalformedData);
return Err(DataError::custom("invalid").with_key(CollationJamoV1Marker::KEY));
}

let mut altered_defaults = CollatorOptionsBitField::new();
Expand All @@ -226,7 +225,9 @@ impl Collator {
// `variant_count` isn't stable yet:
// https://github.com/rust-lang/rust/issues/73662
if special_primaries.get().last_primaries.len() <= (MaxVariable::Currency as usize) {
return Err(CollatorError::MalformedData);
return Err(
DataError::custom("invalid").with_key(CollationSpecialPrimariesV1Marker::KEY)
);
}
Some(special_primaries)
} else {
Expand Down
42 changes: 0 additions & 42 deletions components/collator/src/error.rs

This file was deleted.

5 changes: 0 additions & 5 deletions components/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,12 @@ pub mod docs;
// name of that struct without coordination.
mod elements;

mod error;
mod options;
pub mod provider;

extern crate alloc;

pub use comparison::Collator;
pub use error::CollatorError;
pub use options::AlternateHandling;
pub use options::BackwardSecondLevel;
pub use options::CaseFirst;
Expand All @@ -296,6 +294,3 @@ pub use options::MaxVariable;
pub use options::Numeric;
pub use options::ResolvedCollatorOptions;
pub use options::Strength;

#[doc(no_inline)]
pub use CollatorError as Error;
Loading

0 comments on commit d769844

Please sign in to comment.