hashicorp/nomad · error

Job ID contains a space

Error message

Job ID contains a space

What it means

Job.Validate() in nomad/structs rejects Job IDs containing whitespace. The check runs only when the ID is non-empty; any space character in j.ID triggers this error. IDs are used in API paths and raft log entries, so spaces are disallowed.

Solutions

  1. Remove spaces from the job ID, using hyphens or underscores instead (e.g. `id = "my-app"`)
  2. Keep human-readable titles in `name` and a space-free value in `id`
  3. Sanitize generated IDs: replace whitespace with '-' before submitting

Example fix

// before
id = "my app"
// after
id = "my-app"
Defensive patterns

Strategy: validation

Validate before calling

if strings.Contains(j.ID, " ") {
    return fmt.Errorf("job ID %q must not contain spaces", j.ID)
}

Type guard

func isSafeJobID(id string) bool { return id != "" && !strings.ContainsAny(id, " \t\x00") }

Try / catch

if err := job.Validate(); err != nil {
    if strings.Contains(err.Error(), "Job ID contains a space") {
        job.ID = strings.ReplaceAll(job.ID, " ", "-")
    }
}

Prevention

When it happens

Trigger: Registering a job whose `id` field contains a literal space, e.g. `id = "my app"`, via `nomad job run`, the HTTP jobs API, or calling Job.Validate() in Go with j.ID containing ' '.

Common situations: Copy-pasting a job name with spaces into the id field; tooling that substitutes a human label (with spaces) into the ID; quoting mistakes in shell scripts that leave stray spaces in the ID.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at nomad/structs/structs.go:4746

	}

	nj.Periodic = j.Periodic.Copy()
	nj.Meta = maps.Clone(j.Meta)
	nj.ParameterizedJob = j.ParameterizedJob.Copy()
	return nj
}

// Validate is used to check a job for reasonable configuration
func (j *Job) Validate() error {
	var mErr multierror.Error

	if j.Region == "" && j.Multiregion == nil {
		mErr.Errors = append(mErr.Errors, errors.New("Missing job region"))
	}
	if j.ID == "" {
		mErr.Errors = append(mErr.Errors, errors.New("Missing job ID"))
	} else if strings.Contains(j.ID, " ") {
		mErr.Errors = append(mErr.Errors, errors.New("Job ID contains a space"))
	} else if strings.Contains(j.ID, "\000") {
		mErr.Errors = append(mErr.Errors, errors.New("Job ID contains a null character"))
	}
	if j.Name == "" {
		mErr.Errors = append(mErr.Errors, errors.New("Missing job name"))
	} else if strings.Contains(j.Name, "\000") {
		mErr.Errors = append(mErr.Errors, errors.New("Job Name contains a null character"))
	}

	if j.Namespace == "" {
		mErr.Errors = append(mErr.Errors, errors.New("Job must be in a namespace"))
	}
	switch j.Type {
	case JobTypeCore, JobTypeService, JobTypeBatch, JobTypeSystem, JobTypeSysBatch:
	case "":
		mErr.Errors = append(mErr.Errors, errors.New("Missing job type"))
	default:
		mErr.Errors = append(mErr.Errors, fmt.Errorf("Invalid job type: %q", j.Type))

View on GitHub (pinned to 482b49bf1a)