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

fix: de-duplicate message IDs #1973

Merged
merged 5 commits into from
Nov 22, 2021
Merged

fix: de-duplicate message IDs #1973

merged 5 commits into from
Nov 22, 2021

Conversation

zepatrik
Copy link
Member

@zepatrik zepatrik commented Nov 22, 2021

Related issue(s)

closes #1956

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security. vulnerability, I
    confirm that I got green light (please contact
    [email protected]) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

The clidoc util now ensures that there are no duplicate IDs.
It works, as before changing the ID I got this error:

$ make docs/cli
go run ./cmd/clidoc/. .
Unable to validate messages: message ID 1070000 is used more than once: InfoSelfServiceVerification InfoNodeLabel
main.validateAllMessagesExist
        /home/patrik/git/kratos/cmd/clidoc/main.go:267
main.main
        /home/patrik/git/kratos/cmd/clidoc/main.go:127
runtime.main
        /usr/lib/go/src/runtime/proc.go:255
runtime.goexit
        /usr/lib/go/src/runtime/asm_amd64.s:1581
exit status 1
make: *** [Makefile:33: docs/cli] Error 1

clidoc .
.PHONY: docs/cli
docs/cli:
go run ./cmd/clidoc/. .
Copy link
Member Author

@zepatrik zepatrik Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is way easier to manage rebuilding when needed.

for _, spec := range decl.Specs {
value := spec.(*ast.ValueSpec) // safe because decl.Tok is token.CONST
if t, ok := value.Type.(*ast.Ident); ok {
if t.Name == "ID" {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filters to use const's only of type ID (i.e. hard-coded).

allFiles = append(allFiles, f)
}
}
_, err = (&types.Config{Importer: importer.Default()}).Check("text", set, allFiles, info)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gave me a bit of a hard time, as I could not get it to properly resolve imports from modules. Therefore, the warning in the id.go file.

Comment on lines +3 to +4
// This file MUST not have any imports to modules that are not in the standard library.
// Otherwise, `make docs/cli` will fail.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this warning

}
allFiles := make([]*ast.File, 0)
for fn, f := range pack.Files {
if strings.HasSuffix(fn, "/id.go") {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and hence we only load that file (hard-coded).

@aeneasr aeneasr merged commit 9d8e197 into master Nov 22, 2021
@aeneasr aeneasr deleted the fix/duplicate-message-ids branch November 22, 2021 20:32
peturgeorgievv pushed a commit to senteca/kratos-fork that referenced this pull request Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conflicting message IDs for node and verification
2 participants