hashicorp/nomad · error

failed reading template contents

Error message

failed reading template contents: %w

What it means

In the template-render child process, writeTemplate failed reading the rendered template contents piped on stdin (io.Copy from os.Stdin), so the destination file cannot be written and rendering aborts.

Solutions

  1. Check parent process logs for the error passing template contents
  2. Verify pipe/stdio is intact for the subprocess
  3. Retry the template render; check system resource limits
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at client/allocrunner/taskrunner/template/renderer/z_template_render.go:115 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/4c82f5219ebf1237. Report an issue: GitHub.

Appendix: source

Thrown at client/allocrunner/taskrunner/template/renderer/z_template_render.go:115

func writeTemplate() (*renderer.RenderResult, error) {

	var (
		sandboxPath, destPath, perms, user, group string
	)

	flags := flag.NewFlagSet("template-render", flag.ExitOnError)
	flags.StringVar(&sandboxPath, "sandbox-path", "", "")
	flags.StringVar(&destPath, "dest-path", "", "")
	flags.StringVar(&perms, "perms", "", "")
	flags.StringVar(&user, "user", "", "")
	flags.StringVar(&group, "group", "", "")

	flags.Parse(os.Args[3:])

	contents := new(bytes.Buffer)
	_, err := io.Copy(contents, os.Stdin)
	if err != nil {
		return nil, fmt.Errorf("failed reading template contents: %w", err)
	}

	destPath, err = sandbox(sandboxPath, destPath) // platform-specific sandboxing
	if err != nil {
		return nil, fmt.Errorf("failed to sandbox alloc dir %q: %w", sandboxPath, err)
	}

	// perms must parse into a valid file permission
	fileMode := os.FileMode(DefaultFilePerms)
	if perms != "" {
		fileModeInt, err := strconv.ParseUint(perms, 8, 32)
		if err != nil {
			return nil, fmt.Errorf(
				"Invalid file mode %q: Must be a valid octal number: %w", perms, err)

		}
		fileMode = fs.FileMode(fileModeInt)
		if fileMode.Perm() != fileMode {

View on GitHub (pinned to 482b49bf1a)