Skip to content

Commit

Permalink
error handling for pushNewScope
Browse files Browse the repository at this point in the history
  • Loading branch information
escamoteur committed Oct 1, 2024
1 parent 06c9a67 commit 80132fc
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions lib/get_it_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1352,12 +1352,23 @@ class _GetItImplementation implements GetIt {
);
_pushScopeInProgress = true;
_scopes.add(_Scope(name: scopeName, disposeFunc: dispose));
init?.call(this);
if (isFinal) {
_scopes.last.isFinal = true;
try {
init?.call(this);
if (isFinal) {
_scopes.last.isFinal = true;
}
onScopeChanged?.call(true);
} catch (e) {
final failedScope = _scopes.last;

/// prevend any new registrations in this scope
failedScope.isFinal = true;
failedScope.reset(dispose: true);
_scopes.removeLast();
rethrow;
} finally {
_pushScopeInProgress = false;
}
onScopeChanged?.call(true);
_pushScopeInProgress = false;
}

bool _pushScopeInProgress = false;
Expand Down Expand Up @@ -1395,12 +1406,24 @@ class _GetItImplementation implements GetIt {
);
_pushScopeInProgress = true;
_scopes.add(_Scope(name: scopeName, disposeFunc: dispose));
await init?.call(this);
if (isFinal) {
_scopes.last.isFinal = true;
try {
await init?.call(this);

if (isFinal) {
_scopes.last.isFinal = true;
}
onScopeChanged?.call(true);
} catch (e) {
final failedScope = _scopes.last;

/// prevend any new registrations in this scope
failedScope.isFinal = true;
await failedScope.reset(dispose: true);
_scopes.removeLast();
rethrow;
} finally {
_pushScopeInProgress = false;
}
onScopeChanged?.call(true);
_pushScopeInProgress = false;
}

/// Disposes all factories/Singletons that have been registered in this scope
Expand Down Expand Up @@ -1756,9 +1779,6 @@ class _GetItImplementation implements GetIt {
outerFutureGroup.close();
});

/// outerFutureGroup.future returns a Future<List> and not a Future<T>
/// As we know that the actual factory function was added last to the FutureGroup
/// we just use that one
serviceFactory.pendingResult =
outerFutureGroup.future.then((completedFutures) {
return serviceFactory.instance!;
Expand Down

0 comments on commit 80132fc

Please sign in to comment.