hashicorp/nomad · error

minimum number of files is 1; got %d

Error message

minimum number of files is 1; got %d

What it means

This error comes from LogConfig.Validate in nomad/structs/structs.go:7895. Nomad's LogConfig controls task stdout/stderr rotation; MaxFiles must be at least 1 because zero log files makes log collection meaningless. When a job's log block (or API-submitted LogConfig) specifies MaxFiles < 1, the job fails validation with this message.

Source

Thrown at nomad/structs/structs.go:7895

	}
}

// DefaultLogConfig returns the default LogConfig values.
func DefaultLogConfig() *LogConfig {
	return &LogConfig{
		MaxFiles:      10,
		MaxFileSizeMB: 10,
		Disabled:      false,
	}
}

// Validate returns an error if the log config specified are less than the
// minimum allowed. Note that because we have a non-zero default MaxFiles and
// MaxFileSizeMB, we can't validate that they're unset if Disabled=true
func (l *LogConfig) Validate(disk *EphemeralDisk) error {
	var mErr multierror.Error
	if l.MaxFiles < 1 {
		mErr.Errors = append(mErr.Errors, fmt.Errorf("minimum number of files is 1; got %d", l.MaxFiles))
	}
	if l.MaxFileSizeMB < 1 {
		mErr.Errors = append(mErr.Errors, fmt.Errorf("minimum file size is 1MB; got %d", l.MaxFileSizeMB))
	}
	if disk != nil {
		logUsage := (l.MaxFiles * l.MaxFileSizeMB)
		if disk.SizeMB <= logUsage {
			mErr.Errors = append(mErr.Errors,
				fmt.Errorf("log storage (%d MB) must be less than requested disk capacity (%d MB)",
					logUsage, disk.SizeMB))
		}
	}
	return mErr.ErrorOrNil()
}

// Task is a single process typically that is executed as part of a task group.
type Task struct {
	// Name of the task

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Set max_files >= 1 in the job's logs block (default is 10).
  2. To disable log collection entirely, use the task driver/logmon disabled mechanism or set logs disabled = true where supported, not max_files = 0.
  3. If building LogConfig in Go, start from structs.DefaultLogConfig() and only override fields you need.

Example fix

// before
logs {
  max_files     = 0
  max_file_size = 10
}
// after
logs {
  max_files     = 10
  max_file_size = 10
}
Defensive patterns

Strategy: validation

Validate before calling

if lc := job.Groups; lc != nil {
  for _, tg := range job.TaskGroups {
    for _, t := range tg.Tasks {
      if t.LogConfig != nil && t.LogConfig.MaxFiles < 1 {
        return fmt.Errorf("task %s: max_files must be >= 1, got %d", t.Name, t.LogConfig.MaxFiles)
      }
    }
  }
}

Type guard

func validLogFiles(n *int) bool { return n != nil && *n >= 1 }

Prevention

When it happens

Trigger: Submitting a job whose logs block sets max_files = 0 or a negative value; constructing LogConfig{MaxFiles: 0} programmatically and calling Validate(disk); API clients sending log.max_files < 1 in the job JSON/HCL.

Common situations: Users copy HCL templates and set max_files = 0 thinking it disables logging; tools generating job specs compute MaxFiles from an empty config value; misunderstanding that Disabled=true on the log block is the way to turn off logging, not max_files=0.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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