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

Methods are not discovered and not registered from controller struct properly #248

Closed
adrianlop opened this issue Feb 6, 2019 · 3 comments
Assignees
Labels

Comments

@adrianlop
Copy link

adrianlop commented Feb 6, 2019

What version of aah are you using (aah --version)?

aah v0.12.2
cli v0.13.3
go v1.11.5

Does this issue reproduce with the latest release?

yes

What operating system are you using (such as macOS, Linux and Windows)?

MacOS X

What did you do?

aah build

What did you expect to see?

successful build + being able to implement several methods for the same controller struct on several files.

What did you see instead?

ERROR AST: Method 'TriggerPrometheusCall' has incorrect struct recevier 'Controller' on file [/xxx/ops-api/app/controllers/oncaller/prometheus_webhook.go] at line #15

Additional context

If I create an additional struct like I showed you @jeevatkm then the build doesn't throw any error.

@jeevatkm jeevatkm self-assigned this Feb 7, 2019
@jeevatkm jeevatkm changed the title Methods are not loading the struct properly Methods are not discovered and not registered from controller struct properly Feb 7, 2019
jeevatkm added a commit that referenced this issue Feb 7, 2019
@jeevatkm jeevatkm added the bug label Feb 7, 2019
@jeevatkm
Copy link
Member

jeevatkm commented Feb 7, 2019

@adrianlop Found the root issue why it was unable discover the method from controller struct.

I have reviewed you code and also aah AST flow. When Package files gets processed by aah AST code. There are no guaranteed order in the file processing for type & method since its type map[string]*File.

aah/ainsp/program.go

Lines 90 to 104 in 8c41d00

for name, file := range pkgInfo.Pkg.Files {
pkgInfo.Files = append(pkgInfo.Files, filepath.Base(name))
fileImports := make(map[string]string)
for _, decl := range file.Decls {
// Processing imports
pkgInfo.processImports(decl, fileImports)
// Processing types
pkgInfo.processTypes(decl, fileImports)
// Processing methods
processMethods(pkgInfo, prg.RegisteredActions, decl, fileImports)
}
}

So as per your code, controller defined oncaller.go and action methods are defined all three files. Following log lines from random execution on my machine would convey what I mean.

2019-02-06 22:08:01.329 ERROR AST: Method 'TriggerGrafanaCall' has incorrect struct recevier 'Controller' on file [/xxx/ops-api/app/controllers/oncaller/grafana_webhook.go] at line #12
2019-02-06 22:08:01.329 ERROR AST: Method 'TriggerPrometheusCall' has incorrect struct recevier 'Controller' on file [/xxx/ops-api/app/controllers/oncaller/prometheus_webhook.go] at line #15
2019-02-06 22:08:11.154 ERROR AST: Method 'TriggerPrometheusCall' has incorrect struct recevier 'Controller' on file [/xxx/ops-api/app/controllers/oncaller/prometheus_webhook.go] at line #15

So solution to address this issue is to process all types for the package first and then go for processing methods.

jeevatkm added a commit that referenced this issue Feb 7, 2019
…ed log msg (#249)

-  #248 applied the ast go source code processing order fix and corrected
typo on logging info
- version updated to v0.12.3 and readme update
@jeevatkm
Copy link
Member

jeevatkm commented Feb 7, 2019

I have made a release of aah v0.12.3 && cli v0.13.4.

@jeevatkm jeevatkm closed this as completed Feb 7, 2019
@adrianlop
Copy link
Author

just updated the framework and the cli. it's working :)
great stuff @jeevatkm, thank you very much for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants