Skip to content

Commit

Permalink
Throw only on errors not warnings
Browse files Browse the repository at this point in the history
If `false` is passed in `throwOnWarnings` parameter to
`ExceptionFromErrorCode.ThrowIfError` we now ignore any errorcode
that ends in `_WARNING`.
  • Loading branch information
ermshiperete committed Jan 9, 2019
1 parent 4b1c53a commit aa2e046
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [2.5.4] - 2019-01-09

### Fixed

- Normalization of strings that failed to decompose under certain conditions (#106)
- Throw only on errors, not on errorcode that has `WARNING` in name if `throwOnWarnings == false`

## [2.5.3] - 2018-12-17

Expand Down
32 changes: 20 additions & 12 deletions source/icu.net/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,36 +392,44 @@ private static void ThrowIfError(ErrorCode e, string extraInfo, bool throwOnWarn
break;
case ErrorCode.USING_FALLBACK_WARNING:
if (throwOnWarnings)
{
throw new WarningException("Warning: A resource bundle lookup returned a fallback result " + extraInfo);
}

break;
case ErrorCode.USING_DEFAULT_WARNING:
if (throwOnWarnings)
{
throw new WarningException("Warning: A resource bundle lookup returned a result from the root locale " + extraInfo);
}

break;
case ErrorCode.SAFECLONE_ALLOCATED_WARNING:
if (throwOnWarnings)
{
throw new WarningException("Notice: A SafeClone operation required allocating memory " + extraInfo);
}

break;
case ErrorCode.STATE_OLD_WARNING:
throw new WarningException("ICU has to use compatibility layer to construct the service. Expect performance/memory usage degradation. Consider upgrading " + extraInfo);
if (throwOnWarnings)
throw new WarningException("ICU has to use compatibility layer to construct the service. Expect performance/memory usage degradation. Consider upgrading " + extraInfo);

break;
case ErrorCode.STRING_NOT_TERMINATED_WARNING:
throw new WarningException("An output string could not be NUL-terminated because output length==destCapacity. " + extraInfo);
if (throwOnWarnings)
throw new WarningException("An output string could not be NUL-terminated because output length==destCapacity. " + extraInfo);

break;
case ErrorCode.SORT_KEY_TOO_SHORT_WARNING:
throw new WarningException("Number of levels requested in getBound is higher than the number of levels in the sort key " + extraInfo);
if (throwOnWarnings)
throw new WarningException("Number of levels requested in getBound is higher than the number of levels in the sort key " + extraInfo);

break;
case ErrorCode.AMBIGUOUS_ALIAS_WARNING:
throw new WarningException("This converter alias can go to different converter implementations " + extraInfo);
if (throwOnWarnings)
throw new WarningException("This converter alias can go to different converter implementations " + extraInfo);

break;
case ErrorCode.DIFFERENT_UCA_VERSION:
if (throwOnWarnings)
{
throw new WarningException(
"Warning: ucol_open encountered a mismatch between UCA version and collator image version, so the collator was constructed from rules. No impact to further function " + extraInfo);
}

break;
case ErrorCode.ILLEGAL_ARGUMENT_ERROR:
throw new ArgumentException(extraInfo);
Expand Down
2 changes: 1 addition & 1 deletion source/icu.net/icu.net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Authors>SIL International</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/sillsdev/icu-dotnet</PackageProjectUrl>
<Copyright>Copyright © 2007-2018 SIL International</Copyright>
<Copyright>Copyright © 2007-2019 SIL International</Copyright>
<Description>icu.net is a C# Wrapper around ICU4C

This version of icu.net works with (more or less) any version of ICU4C.
Expand Down

0 comments on commit aa2e046

Please sign in to comment.