{"record":{"id":"6b869c666ec3b6e8","repo":"hashicorp/nomad","slug":"task-resources-is-empty","errorCode":null,"errorMessage":"task.Resources is empty","messagePattern":"task\\.Resources is empty","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/docker/driver.go","lineNumber":1034,"sourceCode":"\t}\n\n\treturn idset.Parse[hw.CoreID](string(b)).String(), nil\n}\n\nfunc (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *TaskConfig,\n\timageID string) (createContainerOptions, error) {\n\n\tlogger := d.logger.With(\"task_name\", task.Name)\n\tc := createContainerOptions{}\n\n\t// ensure that PortMap variables are populated early on\n\ttask.Env = taskenv.SetPortMapEnvs(task.Env, driverConfig.PortMap)\n\n\tif task.Resources == nil {\n\t\t// Guard against missing resources. We should never have been able to\n\t\t// schedule a job without specifying this.\n\t\tlogger.Error(\"task.Resources is empty\")\n\t\treturn c, fmt.Errorf(\"task.Resources is empty\")\n\t}\n\n\tmemory, memoryReservation := memoryLimits(driverConfig.MemoryHardLimit,\n\t\ttask.Resources.NomadResources.Memory)\n\tif memory > 0 && memoryReservation > memory {\n\t\treturn c, fmt.Errorf(\"task memory requirements exceed driver hard limit of %d MB\",\n\t\t\tdriverConfig.MemoryHardLimit)\n\t}\n\n\tbinds, err := d.containerBinds(task, driverConfig)\n\tif err != nil {\n\t\treturn c, err\n\t}\n\tlogger.Trace(\"binding volumes\", \"volumes\", binds)\n\n\t// create the config block that will later be consumed by go-dockerclient\n\tconfig := &containerapi.Config{\n\t\tImage:      imageID,","sourceCodeStart":1016,"sourceCodeEnd":1052,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/docker/driver.go#L1016-L1052","documentation":"createContainerConfig guards against a drivers.TaskConfig with nil Resources, which should be impossible for a scheduled task since Nomad always allocates resources. If reached, the driver cannot compute memory/CPU limits for the container and refuses to start it. A structured log is emitted alongside the error.","triggerScenarios":"Calling the docker driver's StartTask (or its internal createContainerConfig) programmatically with a hand-constructed TaskConfig that never had Resources populated — typical of tests, plugins, or tooling driving the driver API directly.","commonSituations":"Custom tooling or unit tests building TaskConfig manually and forgetting task.Resources = &drivers.Resources{...}; an upstream Nomad bug/regression in task config construction.","solutions":["Populate task.Resources (with NomadResources including Memory and CPU) before calling StartTask.","If using the drivers/testutils TaskConfig helper, set resources explicitly rather than relying on defaults.","If this occurs for a normal job submission, file a Nomad issue — scheduled tasks must always carry resources; include the alloc ID and Nomad version."],"exampleFix":"// test harness\n// before\ntaskCfg := drivers.NewTaskConfig(\"alloc\", \"task\")\n// after\ntaskCfg.Resources = &drivers.Resources{NomadResources: &structs.Resources{Memory: 128, CPU: 100}}","handlingStrategy":"type-guard","validationCode":"function assertTaskResources(task) {\n  if (!task || !task.Resources) throw new Error('TaskConfig.Resources must be set before StartTask');\n}","typeGuard":"function hasResources(task) {\n  return task != null && task.Resources != null\n    && typeof task.Resources.NomadResources === 'object';\n}","tryCatchPattern":"try {\n  await driver.StartTask(cfg);\n} catch (err) {\n  if (/task\\.Resources is empty/.test(err.message)) {\n    throw new Error('build TaskConfig with Resources populated (NomadResources.Memory/CPU)');\n  }\n  throw err;\n}","preventionTips":["Always construct TaskConfig via testutil helpers and set Resources explicitly.","Add a unit-test assertion that every TaskConfig fixture has Resources.","For production job submissions, resources comes from Nomad scheduling — never strip it in custom pipelines."],"tags":["docker","nomad","task-config"],"backgroundTag":"missing-required-argument","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}