Skip to content

Commit 0314f7b

Browse files
committed
Exceptions arrangment
1 parent 21409bf commit 0314f7b

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.2.2
2+
3+
* Exceptions arrangment.
4+
15
## 1.2.1+1
26

37
* Remove unused package.

lib/github_colour.dart

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,25 @@ import 'package:meta/meta.dart' show sealed;
1313

1414
import 'src/cache/cache.dart';
1515
import 'src/cache/exception.dart';
16+
import 'src/exception.dart';
1617

1718
export 'src/cache/exception.dart';
19+
export 'src/exception.dart';
1820

1921
const String _src =
2022
"https://raw.githubusercontent.com/ozh/github-colors/master/colors.json";
2123

2224
/// A handler when no language data found in [GitHubColour.find].
2325
typedef LanguageUndefinedHandler = Color Function();
2426

25-
/// An [Error] that can not fetch [GitHubColour] data.
26-
abstract class GitHubColourLoadFailedError extends Error {
27-
final String _message;
28-
29-
GitHubColourLoadFailedError._(
30-
[this._message =
31-
"There are some unexpected error when loading resources."]);
32-
33-
@override
34-
String toString() => _message;
35-
}
36-
3727
/// An [Error] thrown when response unsuccessfully and no cache can be used.
3828
class GitHubColourHTTPLoadFailedError extends GitHubColourLoadFailedError {
3929
/// HTTP response code when fetching colour data.
4030
final int responseCode;
4131

4232
GitHubColourHTTPLoadFailedError._(this.responseCode)
4333
: assert(responseCode != 200),
44-
super._();
34+
super();
4535

4636
@override
4737
String toString() =>
@@ -50,15 +40,16 @@ class GitHubColourHTTPLoadFailedError extends GitHubColourLoadFailedError {
5040

5141
/// An [Error] thrown when no resources available to initalize [GitHubColour].
5242
class GitHubColourNoAvailableResourceError extends GitHubColourLoadFailedError {
53-
GitHubColourNoAvailableResourceError._() : super._();
43+
GitHubColourNoAvailableResourceError._() : super();
5444

5545
@override
5646
String toString() =>
5747
"GitHubColourNoAvailableResourceError: Unable to read GitHub colour data with all available sources.";
5848
}
5949

6050
/// An [Error] when no colour data of the language.
61-
class UndefinedLanguageColourError extends ArgumentError {
51+
class UndefinedLanguageColourError extends ArgumentError
52+
implements GitHubColourLoadFailedError {
6253
/// Undefined language name.
6354
final String undefinedLanguage;
6455

lib/src/cache/exception.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import '../exception.dart';
2+
13
/// An [Error] when detected the cache file has been modified when getting
24
/// online resource failed.
3-
class GitHubColourCacheChecksumMismatchedError extends AssertionError {
5+
class GitHubColourCacheChecksumMismatchedError extends AssertionError
6+
implements GitHubColourLoadFailedError {
47
/// Construct an [Error] for checksum mismatched.
58
GitHubColourCacheChecksumMismatchedError()
69
: super("The cache file has unexpected modifications.");

lib/src/exception.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// An [Error] that can not fetch [GitHubColour] data.
2+
abstract class GitHubColourLoadFailedError extends Error {
3+
final message;
4+
5+
GitHubColourLoadFailedError(
6+
[this.message =
7+
"There are some unexpected error when loading resources."]);
8+
9+
@override
10+
String toString() => message;
11+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: github_colour
22
description: Receive ozh's GitHub colour to Flutter's colour implementation with caching and fallback.
3-
version: 1.2.1+1
3+
version: 1.2.2
44
homepage: https://www.rk0cc.xyz
55
repository: https://github.com/rk0cc/github_colour_flutter
66
environment:

0 commit comments

Comments
 (0)