Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riverpod_graph fails when run against example/marvel and example/pub #2767

Closed
freemansoft opened this issue Jul 23, 2023 · 3 comments
Closed
Assignees
Labels
bug Something isn't working graph

Comments

@freemansoft
Copy link
Contributor

Describe the bug
flutter_graph fails when analyzing several of the example projects

To Reproduce

generating a graph for examples/marvel returns

PS C:\Users\...\riverpod\packages\riverpod_graph> dart run .\bin\riverpod_graph.dart ..\..\examples\marvel\lib -f mermaid
Analyzing C:\Users\...\riverpod\examples\marvel\lib ...
Unhandled exception:
Bad state: No element
#0      Iterable.firstWhere (dart:core/iterable.dart:697:5)
#1      ProviderDependencyVisitor.visitArgumentList (package:riverpod_graph/src/analyze.dart:410:20)
#2      ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:376:50)
#3      InstanceCreationExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:6666:19)
#4      RecursiveAstVisitor.visitInstanceCreationExpression (package:analyzer/dart/ast/visitor.dart:1075:10)
#5      ProviderDependencyVisitor.visitInstanceCreationExpression (package:riverpod_graph/src/analyze.dart:507:20)
#6      InstanceCreationExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:6655:15)
#7      VariableDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:11413:19)
#8      analyze (package:riverpod_graph/src/analyze.dart:73:14)
<asynchronous suspension>

generating a graph for examples\pub returns

PS C:\Users\...\riverpod\packages\riverpod_graph> dart run .\bin\riverpod_graph.dart ..\..\examples\pub\lib -f mermaid   
Analyzing C:\Users\...\riverpod\examples\pub\lib ...
Unhandled exception:
Unsupported operation: unknown expression FetchPackageDetailsProvider(packageName: package.package) InstanceCreationExpressionImpl
#0      parseProviderFromExpression (package:riverpod_graph/src/analyze.dart:662:3)
#1      parseProviderFromExpression (package:riverpod_graph/src/analyze.dart:636:12)
#2      ProviderDependencyVisitor.visitMethodInvocation (package:riverpod_graph/src/analyze.dart:559:32)
#3      MethodInvocationImpl.accept (package:analyzer/src/dart/ast/ast.dart:7712:50)
#4      ForElementImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:4676:11)
#5      RecursiveAstVisitor.visitForElement (package:analyzer/dart/ast/visitor.dart:943:10)
#6      ForElementImpl.accept (package:analyzer/src/dart/ast/ast.dart:4665:50)
#7      NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:8219:20)
#8      ListLiteralImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7302:15)
#9      RecursiveAstVisitor.visitListLiteral (package:analyzer/dart/ast/visitor.dart:1129:10)
#10     ListLiteralImpl.accept (package:analyzer/src/dart/ast/ast.dart:7292:50)
#11     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:8219:20)
#12     ArgumentListImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:380:16)
#13     RecursiveAstVisitor.visitArgumentList (package:analyzer/dart/ast/visitor.dart:667:10)
#14     ProviderDependencyVisitor.visitArgumentList (package:riverpod_graph/src/analyze.dart:496:11)
#15     ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:376:50)
#16     MethodInvocationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7724:19)
#17     RecursiveAstVisitor.visitMethodInvocation (package:analyzer/dart/ast/visitor.dart:1147:10)
#18     ProviderDependencyVisitor.visitMethodInvocation (package:riverpod_graph/src/analyze.dart:549:11)
#19     MethodInvocationImpl.accept (package:analyzer/src/dart/ast/ast.dart:7712:50)
#20     ReturnStatementImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:9222:18)
#21     RecursiveAstVisitor.visitReturnStatement (package:analyzer/dart/ast/visitor.dart:1250:10)
#22     ReturnStatementImpl.accept (package:analyzer/src/dart/ast/ast.dart:9218:50)
#23     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:8219:20)
#24     BlockImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1095:17)
#25     RecursiveAstVisitor.visitBlock (package:analyzer/dart/ast/visitor.dart:709:10)
#26     BlockImpl.accept (package:analyzer/src/dart/ast/ast.dart:1091:50)
#27     BlockFunctionBodyImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1050:12)
#28     RecursiveAstVisitor.visitBlockFunctionBody (package:analyzer/dart/ast/visitor.dart:715:10)
#29     BlockFunctionBodyImpl.accept (package:analyzer/src/dart/ast/ast.dart:1042:50)
#30     FunctionExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:5354:11)
#31     RecursiveAstVisitor.visitFunctionExpression (package:analyzer/dart/ast/visitor.dart:985:10)
#32     FunctionExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:5343:50)
#33     FunctionDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:5222:25)
#34     ProviderDependencyVisitor.visitArgumentList (package:riverpod_graph/src/analyze.dart:449:39)
#35     ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:376:50)
#36     SuperConstructorInvocationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:10229:19)
#37     RecursiveAstVisitor.visitSuperConstructorInvocation (package:analyzer/dart/ast/visitor.dart:1316:10)
#38     SuperConstructorInvocationImpl.accept (package:analyzer/src/dart/ast/ast.dart:10224:15)
#39     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:8219:20)
#40     ConstructorDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2647:19)
#41     ProviderDependencyVisitor.visitInstanceCreationExpression (package:riverpod_graph/src/analyze.dart:540:27)
#42     InstanceCreationExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:6655:15)
#43     VariableDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:11413:19)
#44     analyze (package:riverpod_graph/src/analyze.dart:73:14)
<asynchronous suspension>

Expected behavior

A graph should be emitted instead of an error. It works correctly for other examples like counter and todo

@freemansoft
Copy link
Contributor Author

freemansoft commented Jul 25, 2023

Found the problem with running graph against examples/marvel

marvel.dart:23 graph fails trying to find a build method with

final repositoryProvider = Provider(MarvelRepository.new);

marvel.dart:23 graph succeeds if MarvalRepository is 8initialized

final repositoryProvider = Provider((ref) => MarvelRepository(ref));

I can do a PR if this is the "right" way to fix this. Otherwise, the code that looks for build() method needs to be refactored.

@rrousselGit
Copy link
Owner

Using a constructor tear-off should be supported.

That's generally how NotifierProviders are used.

@freemansoft
Copy link
Contributor Author

PR #2786 fixes the issue where riverpod_graph doesn't handle xxx.new tearoffs

The problem analyzing examples/pub is not addressed in the PR. I believe the problem with examples/pub is that there is a provider missing the call method being checked against in the analyzer's visitInstanceCreationExpression. That leaves the node analyzed as an InstanceCreationExpressionImpl which is an unexpected type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working graph
Projects
None yet
Development

No branches or pull requests

2 participants