kubernetes/kops · error

task is nil

Error message

task is nil

What it means

A nil-check guard in TaskKey: the caller passed a nil fi.CloudupTask (nil interface or nil pointer stored in the interface) to the helper that builds the canonical "TypeName/name" map key. It fires before any type assertion, so a nil task never reaches the HasName check.

Source

Thrown at upup/pkg/fi/cloudup/template_functions.go:578

	var keys []string
	for key := range tasks {
		if strings.HasPrefix(key, prefix) {
			keys = append(keys, key)
		}
	}
	sort.Strings(keys)

	matches := make([]fi.CloudupTask, 0, len(keys))
	for _, key := range keys {
		matches = append(matches, tasks[key])
	}
	return matches, nil
}

// TaskKey returns the canonical task key used in the task map.
func (tf *TemplateFunctions) TaskKey(task fi.CloudupTask) (string, error) {
	if task == nil {
		return "", fmt.Errorf("task is nil")
	}
	hasName, ok := task.(fi.HasName)
	if !ok {
		return "", fmt.Errorf("task %T does not implement HasName", task)
	}
	name := fi.ValueOf(hasName.GetName())
	if name == "" {
		return "", fmt.Errorf("task %T did not have a name", task)
	}
	return fi.TypeNameForTask(task) + "/" + name, nil
}

// SharedVPC is a simple helper function which makes the templates for a shared VPC clearer
func (tf *TemplateFunctions) SharedVPC() bool {
	return tf.Cluster.SharedVPC()
}

// GetInstanceGroup returns the instance group with the specified name

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Fix the caller to pass a non-nil task; typically a task lookup or construction returned nil and the error was ignored
  2. Check for nil at the call site before invoking TaskKey
  3. If using Task helpers from templates, verify the referenced task exists (see Task/"task not found")
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at upup/pkg/fi/cloudup/template_functions.go:578 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/55f9a8c82f2f1e42. Report an issue: GitHub.