ory/kratos · error

expected to find const

Error message

expected to find const %s in text/id.go

What it means

validateAllMessages cross-checks each entry in the generator's messages map against the constants declared in text/id.go. A message known to the generator has no matching const declaration in that file, so the registry references a constant that does not exist in source.

Solutions

  1. Add the missing const with the message's name to text/id.go
  2. If the message was removed, delete its entry from the messages map in cmd/clidoc/main.go
  3. Keep the const name exactly matching what the generator expects
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cmd/clidoc/main.go:389 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ory/kratos@b86338da04 (2026-09-07). Data as JSON: /api/errors/09e5b1387eac94b0. Report an issue: GitHub.

Appendix: source

Thrown at cmd/clidoc/main.go:389

	for _, f := range pack.Files {
		for _, d := range f.Decls {
			switch decl := d.(type) {
			case *ast.FuncDecl:
				if name := decl.Name.String(); decl.Name.IsExported() && strings.HasPrefix(name, "New") {
					if _, ok := messages[name]; !ok {
						return errors.Errorf("expected to find message %s in the list for the documentation generation but could not", name)
					}
				}
			case *ast.GenDecl:
				if decl.Tok == token.CONST {
					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" {
								for _, name := range value.Names {
									c := info.ObjectOf(name)
									if c == nil {
										return errors.Errorf("expected to find const %s in text/id.go", name.Name)
									}
									usedIDs = append(usedIDs, message{
										ID:   c.(*types.Const).Val().ExactString(),
										Name: name.Name,
									})
								}
							}
						}
					}
				}
			}
		}
	}

	sort.Slice(usedIDs, func(i, j int) bool {
		return usedIDs[i].ID < usedIDs[j].ID
	})
	for i := 1; i < len(usedIDs); i++ {

View on GitHub (pinned to b86338da04)