@@ -3,6 +3,7 @@ import 'package:flutter_policy_engine/src/core/interfaces/i_policy_evaluator.dar
3
3
import 'package:flutter_policy_engine/src/core/interfaces/i_policy_storage.dart' ;
4
4
import 'package:flutter_policy_engine/src/core/memory_policy_storage.dart' ;
5
5
import 'package:flutter_policy_engine/src/core/role_evaluator.dart' ;
6
+ import 'package:flutter_policy_engine/src/exceptions/policy_sdk_exception.dart' ;
6
7
import 'package:flutter_policy_engine/src/models/role.dart' ;
7
8
import 'package:flutter_policy_engine/src/utils/external_asset_handler.dart' ;
8
9
import 'package:flutter_policy_engine/src/utils/json_handler.dart' ;
@@ -66,9 +67,7 @@ class PolicyManager extends ChangeNotifier {
66
67
/// are JSON representations of [Role] objects.
67
68
///
68
69
/// Throws:
69
- /// - [JsonParseException] if policy parsing fails completely
70
- /// - [FormatException] if the JSON data is malformed
71
- /// - [ArgumentError] if policy parsing fails
70
+ /// - [PolicySDKException] if initialization fails for any reason, including malformed JSON, parsing errors, or storage issues.
72
71
Future <void > initialize (Map <String , dynamic > jsonPolicies) async {
73
72
try {
74
73
LogHandler .info (
@@ -171,8 +170,10 @@ class PolicyManager extends ChangeNotifier {
171
170
operation: 'policy_manager_initialize_error' ,
172
171
);
173
172
174
- // Re-throw to allow caller to handle the error
175
- rethrow ;
173
+ throw PolicySDKException (
174
+ 'Failed to initialize policy manager' ,
175
+ exception: e is Exception ? e : null ,
176
+ );
176
177
}
177
178
}
178
179
@@ -236,20 +237,8 @@ class PolicyManager extends ChangeNotifier {
236
237
///
237
238
/// ## Throws
238
239
///
239
- /// * [ArgumentError] - If [assetPath] is empty or null
240
- ///
241
- /// ## Dependencies
242
- ///
243
- /// This method depends on:
244
- /// * [ExternalAssetHandler] - For loading and parsing the asset file
245
- /// * [initialize] - For processing the loaded policy data
246
- /// * [LogHandler] - For error logging and debugging
247
- ///
240
+ /// * [PolicySDKException] - If initialization fails for any reason, including malformed JSON, parsing errors, or storage issues.
248
241
Future <void > initializeFromJsonAssets (String assetPath) async {
249
- if (assetPath.isEmpty) {
250
- throw ArgumentError ('Asset path cannot be empty' );
251
- }
252
-
253
242
try {
254
243
final assetHandler = ExternalAssetHandler (assetPath: assetPath);
255
244
final jsonPolicies = await assetHandler.loadAssets ();
@@ -368,6 +357,11 @@ class PolicyManager extends ChangeNotifier {
368
357
context: {'asset_path' : assetPath},
369
358
operation: 'policy_manager_initialize_from_json_assets_error' ,
370
359
);
360
+
361
+ throw PolicySDKException (
362
+ 'Failed to initialize policy manager from JSON assets' ,
363
+ exception: e is Exception ? e : null ,
364
+ );
371
365
}
372
366
}
373
367
@@ -402,11 +396,11 @@ class PolicyManager extends ChangeNotifier {
402
396
/// [role] must not be null and should have a valid name.
403
397
///
404
398
/// Throws:
405
- /// - [ArgumentError ] if [role] is null or has an invalid name
399
+ /// - [PolicySDKException ] if [role] is null or has an invalid name
406
400
/// - Storage-related exceptions if persistence fails
407
401
Future <void > addRole (Role role) async {
408
402
if (role.name.isEmpty) {
409
- throw ArgumentError ('Role name cannot be empty' );
403
+ throw PolicySDKException ('Role name cannot be empty' );
410
404
}
411
405
412
406
_roles[role.name] = role;
@@ -428,11 +422,11 @@ class PolicyManager extends ChangeNotifier {
428
422
/// [roleName] must not be null or empty.
429
423
///
430
424
/// Throws:
431
- /// - [ArgumentError ] if [roleName] is null or empty
425
+ /// - [PolicySDKException ] if [roleName] is null or empty
432
426
/// - Storage-related exceptions if persistence fails
433
427
Future <void > removeRole (String roleName) async {
434
428
if (roleName.isEmpty) {
435
- throw ArgumentError ('Role name cannot be empty' );
429
+ throw PolicySDKException ('Role name cannot be empty' );
436
430
}
437
431
438
432
_roles.remove (roleName);
@@ -454,11 +448,11 @@ class PolicyManager extends ChangeNotifier {
454
448
/// [role] must not be null and should have a valid name.
455
449
///
456
450
/// Throws:
457
- /// - [ArgumentError ] if [roleName] is null/empty or [role] is null/invalid
451
+ /// - [PolicySDKException ] if [roleName] is null/empty or [role] is null/invalid
458
452
/// - Storage-related exceptions if persistence fails
459
453
Future <void > updateRole (String roleName, Role role) async {
460
454
if (roleName.isEmpty && role.name.isEmpty) {
461
- throw ArgumentError ('Role name cannot be empty' );
455
+ throw PolicySDKException ('Role name cannot be empty' );
462
456
}
463
457
464
458
_roles[roleName] = role;
0 commit comments