ory/kratos · error

unable to write messages json to

Error message

unable to write messages json to %s

What it means

generateElements sorted the known messages and delegated to writeMessagesJson to serialize them into the message file, and that write failed. The error is wrapped, so the root cause is reported by the inner call - commonly JSON marshalling of a message or a write error on the already-opened file.

Solutions

  1. Inspect the wrapped error to see whether marshalling or the file write failed
  2. If marshalling: fix the message struct that cannot serialize (check for channels, funcs, or cycles)
  3. If writing: check disk space and permissions on the message file path
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at cmd/clidoc/main.go:428

		}
	}

	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)