ory/kratos · error

unable to open or create message file at

Error message

unable to open or create message file at %s

What it means

generateElements could not open (or create) the message file at the given path with append/create/write-only mode. The wrapped os.OpenFile error indicates a filesystem-level problem: the path may not exist and be uncreatable, permissions may be insufficient, or the parent directory is missing.

Solutions

  1. Check that the parent directory of the message file path exists
  2. Fix permissions so the running user can create/append to the file (0o644 target)
  3. Pass a writable, absolute path to the generator
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cmd/clidoc/main.go:420 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/edcc8732b8941016. Report an issue: GitHub.

Appendix: source

Thrown at cmd/clidoc/main.go:420

	}

	sort.Slice(usedIDs, func(i, j int) bool {
		return usedIDs[i].ID < usedIDs[j].ID
	})
	for i := 1; i < len(usedIDs); i++ {
		if usedIDs[i].ID == usedIDs[i-1].ID {
			return errors.Errorf("message ID %s is used more than once: %s %s", usedIDs[i].ID, usedIDs[i].Name, usedIDs[i-1].Name)
		}
	}

	return nil
}

func generateElements(messageFilePath string) error {
	// If the file at messageFilePath does not exist, create it
	f, err := os.OpenFile(messageFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) // #nosec
	if err != nil {
		return errors.Wrapf(err, "unable to open or create message file at %s", messageFilePath)
	}
	if err := f.Close(); err != nil {
		return errors.Wrapf(err, "unable to close message file at %s", messageFilePath)
	}

	sortedMessages := sortMessages()
	if err := writeMessagesJson(messageFilePath, sortedMessages); err != nil {
		return errors.Wrapf(err, "unable to write messages json to %s", messageFilePath)
	}
	return nil
}

View on GitHub (pinned to b86338da04)