ory/kratos · error

unable to parse text directory

Error message

unable to parse text directory

What it means

During documentation generation, go/parser.ParseDir failed to parse the Go sources in the messages text package directory. The underlying error is wrapped, meaning one or more files in that directory have syntax errors or cannot be read; this is a build-time failure of the clidoc tool, not a runtime user error.

Solutions

  1. Verify the path passed to validateAllMessages points to the text package directory and exists before parsing
  2. Ensure the directory contains only valid Go source files; move stray non-Go files elsewhere
  3. Check for syntax errors in the .go files under the text directory with go build or go vet
  4. Confirm the process has read permission on the directory
  5. Pass a cleaned absolute path (e.g. via filepath.Abs) to avoid relative-path resolution issues
Defensive patterns

Strategy: validation

When it happens

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

Common situations: See trigger scenarios.

Understand the failure class


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

Appendix: source

Thrown at cmd/clidoc/main.go:346

	}

	if err := f.Close(); err != nil {
		return err
	}

	return nil
}

func validateAllMessages(path string) error {
	type message struct {
		ID, Name string
	}

	usedIDs := make([]message, 0, len(messages))
	set := token.NewFileSet()
	packs, err := parser.ParseDir(set, path, nil, 0)
	if err != nil {
		return errors.Wrapf(err, "unable to parse text directory")
	}
	info := &types.Info{
		Defs: make(map[*ast.Ident]types.Object),
	}

	//nolint:staticcheck
	var pack *ast.Package
	for _, p := range packs {
		if p.Name == "text" {
			pack = p
			break
		}
	}
	allFiles := make([]*ast.File, 0)
	for fn, f := range pack.Files {
		if strings.HasSuffix(fn, "/id.go") {
			allFiles = append(allFiles, f)
		}

View on GitHub (pinned to b86338da04)