Repository: containerd/containerd
File: client/task.go (Go)

Code before:
	// https://github.com/containerd/containerd/issues/11568
	runtimeOptions typeurl.Any
}

// Runtime name for the container
func (i *TaskInfo) Runtime() string {
	return i.runtime
}

func (i *TaskInfo) getRuncOptions() (*options.Options, error) {
	if i.Options != nil {
		opts, ok := i.Options.(*options.Options)
		if !ok {
			return nil, errors.New("invalid runtime v2 options format")
		}
		return opts, nil
	}

	opts := &options.Options{}
	if i.runtimeOptions != nil && i.runtimeOptions.GetValue() != nil {
		if err := typeurl.UnmarshalTo(i.runtimeOptions, opts); err != nil {
			return nil, err
		}
	}
	i.Options = opts
	return opts, nil
}

// Task is the executable object within containerd
type Task interface {
	Process

	// Pause suspends the execution of the task
	Pause(context.Context) error
	// Resume the execution of the task
	Resume(context.Context) error
	// Exec creates a new process inside the task
	Exec(context.Context, string, *specs.Process, cio.Creator) (Process, error)
	// Pids returns a list of system specific process ids inside the task
	Pids(context.Context) ([]ProcessInfo, error)
	// Checkpoint serializes the runtime and memory information of a task into an
	// OCI Index that can be pushed and pulled from a remote resource.
	//
	// Additional software like CRIU maybe required to checkpoint and restore tasks
	// NOTE: Checkpoint supports to dump task information to a directory, in this way,
	// an empty OCI Index will be returned.
	Checkpoint(context.Context, ...CheckpointTaskOpts) (Image, error)
	// Update modifies executing tasks with updated settings
	Update(context.Context, ...UpdateTaskOpts) error
	// LoadProcess loads a previously created exec'd process
	LoadProcess(context.Context, string, cio.Attach) (Process, error)

Review comment (bug):
suggestion:

```go
return nil, fmt.Errorf("failed to get runtime v2 options: %w", err)
```

Code after:
	// https://github.com/containerd/containerd/issues/11568
	runtimeOptions typeurl.Any
}

// Runtime name for the container
func (i *TaskInfo) Runtime() string {
	return i.runtime
}

// getRuncOptions returns a reference to the runtime options for use by the task.
// If the set of options is not set by the opts passed into the NewTask creation
// this function first attempts to initialize the runtime options with a copy of the runtimeOptions,
// otherwise an empty set of options is assigned and returned
func (i *TaskInfo) getRuncOptions() (*options.Options, error) {
	if i.Options != nil {
		opts, ok := i.Options.(*options.Options)
		if !ok {
			return nil, errors.New("invalid runtime v2 options format")
		}
		return opts, nil
	}

	opts := &options.Options{}
	if i.runtimeOptions != nil && i.runtimeOptions.GetValue() != nil {
		if err := typeurl.UnmarshalTo(i.runtimeOptions, opts); err != nil {
			return nil, fmt.Errorf("failed to get runtime v2 options: %w", err)
		}
	}
	i.Options = opts
	return opts, nil
}

// Task is the executable object within containerd
type Task interface {
	Process

	// Pause suspends the execution of the task
	Pause(context.Context) error
	// Resume the execution of the task
	Resume(context.Context) error
	// Exec creates a new process inside the task
	Exec(context.Context, string, *specs.Process, cio.Creator) (Process, error)
	// Pids returns a list of system specific process ids inside the task
	Pids(context.Context) ([]ProcessInfo, error)
	// Checkpoint serializes the runtime and memory information of a task into an
	// OCI Index that can be pushed and pulled from a remote resource.
	//
	// Additional software like CRIU maybe required to checkpoint and restore tasks
	// NOTE: Checkpoint supports to dump task information to a directory, in this way,
	// an empty OCI Index will be returned.
	Checkpoint(context.Context, ...CheckpointTaskOpts) (Image, error)