You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-20Lines changed: 32 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,8 @@ A Dart package defining an abstract interface (`HtKVStorageService`) for key-val
6
6
7
7
* Defines a clear contract for basic key-value operations (read, write, delete) for common data types (`String`, `bool`, `int`, `double`).
8
8
* Includes a `clearAll` method for removing all entries.
9
-
* Provides a `StorageKeys` class example to avoid magic strings.
9
+
* Provides a `StorageKey` enum to avoid magic strings, promoting type safety. Use the `stringValue` getter for the actual key string.
10
+
* Defines a set of custom `StorageException` subclasses (`StorageWriteException`, `StorageReadException`, `StorageDeleteException`, `StorageClearException`, `StorageKeyNotFoundException`, `StorageTypeMismatchException`) to handle specific storage errors.
This package uses [Very Good Analysis](https://pub.dev/packages/very_good_analysis) for static analysis and aims for high test coverage.
103
+
## Error Handling
88
104
89
-
To run tests and generate coverage:
90
-
91
-
```sh
92
-
dart pub global activate coverage 1.2.0 # Activate coverage tool if needed
93
-
dart test --coverage=coverage
94
-
dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info
95
-
```
105
+
The `HtKVStorageService` methods may throw specific exceptions derived from `StorageException` upon failure:
96
106
97
-
To view the HTML coverage report (requires `lcov` and `genhtml`):
107
+
* `StorageWriteException`: Thrown by `write*` methods on failure.
108
+
* `StorageReadException`: Thrown by `read*` methods on general read failure.
109
+
* `StorageDeleteException`: Thrown by `delete` on failure.
110
+
* `StorageClearException`: Thrown by `clearAll` on failure.
111
+
* `StorageKeyNotFoundException`: May be thrown by `delete` if the key doesn't exist (implementation-dependent). `read*` methods typically return `null` or a default value instead.
112
+
* `StorageTypeMismatchException`: Thrown by `read*` methods if the stored data type doesn't match the expected type.
98
113
99
-
```sh
100
-
genhtml coverage/lcov.info -o coverage/
101
-
open coverage/index.html # On macOS/Linux
102
-
# start coverage/index.html # On Windows
114
+
Implementations should handle these exceptions appropriately (e.g., using `try-catch` blocks).
0 commit comments