Skip to content

Commit

Permalink
Fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit committed Feb 10, 2024
1 parent eccd762 commit 91c6fb5
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,26 @@ class ClassBasedProviderDeclaration extends GeneratorProviderDeclaration {
);
}

final defaultConstructor = node.members
.whereType<ConstructorDeclaration>()
final constructors =
node.members.whereType<ConstructorDeclaration>().toList();
final defaultConstructor = constructors
.firstWhereOrNull((constructor) => constructor.name == null);
if (defaultConstructor == null && constructors.isNotEmpty) {
errorReporter?.call(
RiverpodAnalysisError(
'Classes annotated with @riverpod must have a default constructor.',
targetNode: node,
targetElement: node.declaredElement,
),
);
}
// TODO changelog report error if default constructor is missing
if (defaultConstructor == null ||
if (defaultConstructor != null &&
defaultConstructor.parameters.parameters.any((e) => e.isRequired)) {
errorReporter?.call(
RiverpodAnalysisError(
'Classes annotated with @riverpod must have a default constructor '
'with no required parameters.',
'The default constructor of classes annotated with @riverpod '
'cannot have required parameters.',
targetNode: node,
targetElement: node.declaredElement,
),
Expand Down

0 comments on commit 91c6fb5

Please sign in to comment.