hashicorp/nomad · error

Job Name contains a null character

Error message

Job Name contains a null character

What it means

Job.Validate() rejects Job Names containing a NUL byte ("\000"). Like the ID check, this guards against control characters that break downstream string handling and storage. It applies only when the Name is non-empty.

Source

Thrown at nomad/structs/structs.go:4753

// 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))
	}
	if len(j.Datacenters) == 0 && !j.IsMultiregion() {
		mErr.Errors = append(mErr.Errors, errors.New("Missing job datacenters"))
	} else {
		for _, v := range j.Datacenters {
			if v == "" {
				mErr.Errors = append(mErr.Errors, errors.New("Job datacenter must be non-empty string"))

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Sanitize the name: strings.ReplaceAll(name, "\x00", "") before submission
  2. Validate user-supplied names with ^[^\x00]+$ at your API boundary
  3. Log the name with %q to reveal hidden control characters when debugging

Example fix

// before
job.Name = userInput
// after
job.Name = strings.ReplaceAll(userInput, "\x00", "")
Defensive patterns

Strategy: validation

Validate before calling

if strings.Contains(j.Name, "\x00") {
    return fmt.Errorf("job name contains a null character")
}

Type guard

func isSafeJobName(name string) bool { return name != "" && !strings.ContainsRune(name, '\x00') }

Try / catch

if err := job.Validate(); err != nil {
    if strings.Contains(err.Error(), "Job Name contains a null character") {
        job.Name = strings.ReplaceAll(job.Name, "\x00", "")
    }
}

Prevention

When it happens

Trigger: Registering a job whose `name` field contains an embedded null byte, usually from programmatic construction (j.Name containing "\x00") or corrupted/deserialized input passed to Job.Validate().

Common situations: Untrusted or binary-derived input feeding the job name; string truncation bugs introducing NULs; injection attempts through job-submission APIs.

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/531ba042f140f163. Report an issue: GitHub.