ronantakizawa/codereview-bench huggingface dataset:
Repository: moby/moby
File: daemon/server/router/container/backend.go (Go)

Code before:
package container

import (
	"context"
	"io"

	containerpkg "github.com/docker/docker/daemon/container"
	"github.com/moby/go-archive"
	"github.com/moby/moby/api/types/backend"
	"github.com/moby/moby/api/types/container"
	"github.com/moby/moby/api/types/filters"
)

// execBackend includes functions to implement to provide exec functionality.
type execBackend interface {
	ContainerExecCreate(name string, options *container.ExecOptions) (string, error)
	ContainerExecInspect(id string) (*backend.ExecInspect, error)
	ContainerExecResize(ctx context.Context, name string, height, width uint32) error
	ContainerExecStart(ctx context.Context, name string, options backend.ExecStartConfig) error
	ExecExists(name string) (bool, error)
}

// copyBackend includes functions to implement to provide container copy functionality.
type copyBackend interface {
	ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *container.PathStat, err error)
	ContainerExport(ctx context.Context, name string, out io.Writer) error
	ContainerExtractToDir(name, path string, copyUIDGID, noOverwriteDirNonDir bool, content io.Reader) error
	ContainerStatPath(name string, path string) (stat *container.PathStat, err error)
}

// stateBackend includes functions to implement to provide container state lifecycle functionality.
type stateBackend interface {

Review comment (suggestion):
Alternatively, we could move it to `api/types/backend` to indicate "internal" (but public); ideally, I'd still want to get rid of these though 😂 

Code after:
package container

import (
	"context"
	"io"

	containerpkg "github.com/docker/docker/daemon/container"
	"github.com/docker/docker/daemon/server/backend"
	"github.com/moby/go-archive"
	"github.com/moby/moby/api/types/container"
	"github.com/moby/moby/api/types/filters"
)

// execBackend includes functions to implement to provide exec functionality.
type execBackend interface {
	ContainerExecCreate(name string, options *container.ExecOptions) (string, error)
	ContainerExecInspect(id string) (*backend.ExecInspect, error)
	ContainerExecResize(ctx context.Context, name string, height, width uint32) error
	ContainerExecStart(ctx context.Context, name string, options backend.ExecStartConfig) error
	ExecExists(name string) (bool, error)
}

// copyBackend includes functions to implement to provide container copy functionality.
type copyBackend interface {
	ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *container.PathStat, err error)
	ContainerExport(ctx context.Context, name string, out io.Writer) error
	ContainerExtractToDir(name, path string, copyUIDGID, allowOverwriteDirWithFile bool, content io.Reader) error
	ContainerStatPath(name string, path string) (stat *container.PathStat, err error)
}

// stateBackend includes functions to implement to provide container state lifecycle functionality.
type stateBackend interface {
Repository: moby/moby
File: integration/network/network_test.go (Go)

Code before:
			t.Parallel()

			res, body, err := request.Get(ctx, ep, request.JSON)
			assert.NilError(t, err)
			assert.Equal(t, res.StatusCode, http.StatusOK)

			buf, err := request.ReadBody(body)
			assert.NilError(t, err)
			var nws []networktypes.Inspect
			err = json.Unmarshal(buf, &nws)
			assert.NilError(t, err)
			assert.Assert(t, len(nws) > 0)
		})
	}
}

func TestAPINetworkGetDefaults(t *testing.T) {
	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	var defaults []string
	if runtime.GOOS == "windows" {
		defaults = []string{"nat", "none"}
	} else {
		defaults = []string{"bridge", "host", "none"}
	}

	for _, netName := range defaults {
		assert.Assert(t, IsNetworkAvailable(ctx, apiClient, netName))
	}
}

func TestAPINetworkFilter(t *testing.T) {
	var networkName string
	if runtime.GOOS == "windows" {
		networkName = "nat"
	} else {
		networkName = "bridge"
	}

	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	networks, err := apiClient.NetworkList(ctx, networktypes.ListOptions{
		Filters: filters.NewArgs(filters.Arg("name", networkName)),
	})

	assert.NilError(t, err)

	found := false
	for _, network := range networks {

Review comment (suggestion):
```suggestion
	defaults := []string{"bridge", "host", "none"}
	if runtime.GOOS == "windows" {
		defaults = []string{"nat", "none"}
	}
```

Code after:
			t.Parallel()

			res, body, err := request.Get(ctx, ep, request.JSON)
			assert.NilError(t, err)
			assert.Equal(t, res.StatusCode, http.StatusOK)

			buf, err := request.ReadBody(body)
			assert.NilError(t, err)
			var nws []networktypes.Inspect
			err = json.Unmarshal(buf, &nws)
			assert.NilError(t, err)
			assert.Assert(t, len(nws) > 0)
		})
	}
}

func TestAPINetworkGetDefaults(t *testing.T) {
	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	defaults := []string{"bridge", "host", "none"}
	if testEnv.DaemonInfo.OSType == "windows" {
		defaults = []string{"nat", "none"}
	}

	for _, netName := range defaults {
		assert.Assert(t, IsNetworkAvailable(ctx, apiClient, netName))
	}
}

func TestAPINetworkFilter(t *testing.T) {
	networkName := "bridge"
	if testEnv.DaemonInfo.OSType == "windows" {
		networkName = "nat"
	}

	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	networks, err := apiClient.NetworkList(ctx, client.NetworkListOptions{
		Filters: filters.NewArgs(filters.Arg("name", networkName)),
	})

	assert.NilError(t, err)

	found := false
	for _, network := range networks {
		if network.Name == networkName {
			found = true
		}
	}
Repository: moby/moby
File: integration/network/network_test.go (Go)

Code before:
	}
}

func TestAPINetworkGetDefaults(t *testing.T) {
	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	var defaults []string
	if runtime.GOOS == "windows" {
		defaults = []string{"nat", "none"}
	} else {
		defaults = []string{"bridge", "host", "none"}
	}

	for _, netName := range defaults {
		assert.Assert(t, IsNetworkAvailable(ctx, apiClient, netName))
	}
}

func TestAPINetworkFilter(t *testing.T) {
	var networkName string
	if runtime.GOOS == "windows" {
		networkName = "nat"
	} else {
		networkName = "bridge"
	}

	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	networks, err := apiClient.NetworkList(ctx, networktypes.ListOptions{
		Filters: filters.NewArgs(filters.Arg("name", networkName)),
	})

	assert.NilError(t, err)

	found := false
	for _, network := range networks {
		if network.Name == networkName {
			found = true
		}
	}
	assert.Assert(t, found, fmt.Sprintf("%s is not found", networkName))
}


Review comment (suggestion):
```suggestion
	nwName := "bridge"
	if runtime.GOOS == "windows" {
		nwName = "nat"
	}
```

Code after:
	}
}

func TestAPINetworkGetDefaults(t *testing.T) {
	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	defaults := []string{"bridge", "host", "none"}
	if testEnv.DaemonInfo.OSType == "windows" {
		defaults = []string{"nat", "none"}
	}

	for _, netName := range defaults {
		assert.Assert(t, IsNetworkAvailable(ctx, apiClient, netName))
	}
}

func TestAPINetworkFilter(t *testing.T) {
	networkName := "bridge"
	if testEnv.DaemonInfo.OSType == "windows" {
		networkName = "nat"
	}

	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	networks, err := apiClient.NetworkList(ctx, client.NetworkListOptions{
		Filters: filters.NewArgs(filters.Arg("name", networkName)),
	})

	assert.NilError(t, err)

	found := false
	for _, network := range networks {
		if network.Name == networkName {
			found = true
		}
	}
	assert.Assert(t, found, fmt.Sprintf("%s is not found", networkName))
}
Repository: moby/moby
File: integration/network/network_test.go (Go)

Code before:

	for _, ep := range endpoints {
		t.Run(ep, func(t *testing.T) {
			ctx := testutil.StartSpan(ctx, t)
			t.Parallel()

			res, body, err := request.Get(ctx, ep, request.JSON)
			assert.NilError(t, err)
			assert.Equal(t, res.StatusCode, http.StatusOK)

			buf, err := request.ReadBody(body)
			assert.NilError(t, err)
			var nws []networktypes.Inspect
			err = json.Unmarshal(buf, &nws)
			assert.NilError(t, err)
			assert.Assert(t, len(nws) > 0)
		})
	}
}

func TestAPINetworkGetDefaults(t *testing.T) {
	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	defaults := []string{"bridge", "host", "none"}
	if runtime.GOOS == "windows" {
		defaults = []string{"nat", "none"}
	}

	for _, netName := range defaults {
		assert.Assert(t, IsNetworkAvailable(ctx, apiClient, netName))
	}
}

func TestAPINetworkFilter(t *testing.T) {
	networkName := "bridge"
	if runtime.GOOS == "windows" {
		networkName = "nat"
	}

	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	networks, err := apiClient.NetworkList(ctx, networktypes.ListOptions{
		Filters: filters.NewArgs(filters.Arg("name", networkName)),
	})

	assert.NilError(t, err)

	found := false
	for _, network := range networks {

Review comment (suggestion):
Probably more correct would be to check the daemon's platform. We don't currently do so, but these tests _could_ be run from a Linux environment testing a Windows daemon;


```go
	if testEnv.DaemonInfo.OSType == "windows" {
```

Code after:

	for _, ep := range endpoints {
		t.Run(ep, func(t *testing.T) {
			ctx := testutil.StartSpan(ctx, t)
			t.Parallel()

			res, body, err := request.Get(ctx, ep, request.JSON)
			assert.NilError(t, err)
			assert.Equal(t, res.StatusCode, http.StatusOK)

			buf, err := request.ReadBody(body)
			assert.NilError(t, err)
			var nws []networktypes.Inspect
			err = json.Unmarshal(buf, &nws)
			assert.NilError(t, err)
			assert.Assert(t, len(nws) > 0)
		})
	}
}

func TestAPINetworkGetDefaults(t *testing.T) {
	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	defaults := []string{"bridge", "host", "none"}
	if testEnv.DaemonInfo.OSType == "windows" {
		defaults = []string{"nat", "none"}
	}

	for _, netName := range defaults {
		assert.Assert(t, IsNetworkAvailable(ctx, apiClient, netName))
	}
}

func TestAPINetworkFilter(t *testing.T) {
	networkName := "bridge"
	if testEnv.DaemonInfo.OSType == "windows" {
		networkName = "nat"
	}

	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	networks, err := apiClient.NetworkList(ctx, client.NetworkListOptions{
		Filters: filters.NewArgs(filters.Arg("name", networkName)),
	})

	assert.NilError(t, err)

	found := false
	for _, network := range networks {
Repository: moby/moby
File: integration/network/network_test.go (Go)

Code before:
			assert.NilError(t, err)
			var nws []networktypes.Inspect
			err = json.Unmarshal(buf, &nws)
			assert.NilError(t, err)
			assert.Assert(t, len(nws) > 0)
		})
	}
}

func TestAPINetworkGetDefaults(t *testing.T) {
	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	defaults := []string{"bridge", "host", "none"}
	if runtime.GOOS == "windows" {
		defaults = []string{"nat", "none"}
	}

	for _, netName := range defaults {
		assert.Assert(t, IsNetworkAvailable(ctx, apiClient, netName))
	}
}

func TestAPINetworkFilter(t *testing.T) {
	networkName := "bridge"
	if runtime.GOOS == "windows" {
		networkName = "nat"
	}

	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	networks, err := apiClient.NetworkList(ctx, networktypes.ListOptions{
		Filters: filters.NewArgs(filters.Arg("name", networkName)),
	})

	assert.NilError(t, err)

	found := false
	for _, network := range networks {
		if network.Name == networkName {
			found = true
		}
	}
	assert.Assert(t, found, fmt.Sprintf("%s is not found", networkName))
}


Review comment (suggestion):
Same here;

```go
if testEnv.DaemonInfo.OSType == "windows" {
```

Code after:
			assert.NilError(t, err)
			var nws []networktypes.Inspect
			err = json.Unmarshal(buf, &nws)
			assert.NilError(t, err)
			assert.Assert(t, len(nws) > 0)
		})
	}
}

func TestAPINetworkGetDefaults(t *testing.T) {
	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	defaults := []string{"bridge", "host", "none"}
	if testEnv.DaemonInfo.OSType == "windows" {
		defaults = []string{"nat", "none"}
	}

	for _, netName := range defaults {
		assert.Assert(t, IsNetworkAvailable(ctx, apiClient, netName))
	}
}

func TestAPINetworkFilter(t *testing.T) {
	networkName := "bridge"
	if testEnv.DaemonInfo.OSType == "windows" {
		networkName = "nat"
	}

	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	networks, err := apiClient.NetworkList(ctx, client.NetworkListOptions{
		Filters: filters.NewArgs(filters.Arg("name", networkName)),
	})

	assert.NilError(t, err)

	found := false
	for _, network := range networks {
		if network.Name == networkName {
			found = true
		}
	}
	assert.Assert(t, found, fmt.Sprintf("%s is not found", networkName))
}
Repository: moby/moby
File: daemon/health.go (Go)

Code before:
		return nil
	}
	switch config.Test[0] {
	case "CMD":
		return &cmdProbe{shell: false}
	case "CMD-SHELL":
		return &cmdProbe{shell: true}
	case "NONE":
		return nil
	default:
		log.G(context.TODO()).Warnf("Unknown healthcheck type '%s' (expected 'CMD') in container %s", config.Test[0], c.ID)
		return nil
	}
}

// Ensure the health-check monitor is running or not, depending on the current
// state of the container.
// Called from monitor.go, with c locked.
func (daemon *Daemon) updateHealthMonitor(c *container.Container) {
	h := c.State.Health
	if h == nil {
		return // No healthcheck configured
	}

	probe := getProbe(c)
	wantRunning := c.State.Running && !c.State.Paused && probe != nil
	if wantRunning {
		if stop := h.OpenMonitorChannel(); stop != nil {
			go monitor(daemon, c, stop, probe)
		}
	} else {
		h.CloseMonitorChannel()
	}
}

// Reset the health state for a newly-started, restarted or restored container.
// initHealthMonitor is called from monitor.go and we should never be running
// two instances at once.
// Called with c locked.
func (daemon *Daemon) initHealthMonitor(c *container.Container) {
	// If no healthcheck is setup then don't init the monitor
	if getProbe(c) == nil {
		return
	}

	// This is needed in case we're auto-restarting
	daemon.stopHealthchecks(c)

	if h := c.State.Health; h != nil {
		h.SetStatus(containertypes.Starting)
		h.FailingStreak = 0

Review comment (suggestion):
There's another one on line 267 of this file - `monitor().getInterval()` ... `c.State.Health.Health.Status`.

Code after:
		return nil
	}
	switch config.Test[0] {
	case "CMD":
		return &cmdProbe{shell: false}
	case "CMD-SHELL":
		return &cmdProbe{shell: true}
	case "NONE":
		return nil
	default:
		log.G(context.TODO()).Warnf("Unknown healthcheck type '%s' (expected 'CMD') in container %s", config.Test[0], c.ID)
		return nil
	}
}

// Ensure the health-check monitor is running or not, depending on the current
// state of the container.
// Called from monitor.go, with c locked.
func (daemon *Daemon) updateHealthMonitor(c *container.Container) {
	h := c.State.Health
	if h == nil {
		return // No healthcheck configured
	}

	healthProbe := getProbe(c)
	wantRunning := c.State.Running && !c.State.Paused && healthProbe != nil
	if wantRunning {
		if stop := h.OpenMonitorChannel(); stop != nil {
			go monitor(daemon, c, stop, healthProbe)
		}
	} else {
		h.CloseMonitorChannel()
	}
}

// Reset the health state for a newly-started, restarted or restored container.
// initHealthMonitor is called from monitor.go and we should never be running
// two instances at once.
// Called with c locked.
func (daemon *Daemon) initHealthMonitor(c *container.Container) {
	// If no healthcheck is setup then don't init the monitor
	if getProbe(c) == nil {
		return
	}

	// This is needed in case we're auto-restarting
	daemon.stopHealthchecks(c)

	if h := c.State.Health; h != nil {
		h.SetStatus(containertypes.Starting)
		h.Health.FailingStreak = 0
Repository: moby/moby
File: runconfig/errors.go (Go)

Code before:
package runconfig

type invalidJSONError struct {
	Err error
}

func (e invalidJSONError) Error() string {
	return "invalid JSON: " + e.Err.Error()
}

func (e invalidJSONError) Unwrap() error {
	return e.Err
}

func (e invalidJSONError) InvalidParameter() {}


Review comment (bug):
nit: Maybe we could still leave these consts and then use them directly in `cerrdefs.ErrInvalidArgument.WithMessage(...)`?

Also, what's wrong with having `validationError`?

Code after:
package runconfig

import cerrdefs "github.com/containerd/errdefs"

func validationError(msg string) error {
	return cerrdefs.ErrInvalidArgument.WithMessage(msg)
}

type invalidJSONError struct{ error }

func (e invalidJSONError) Error() string {
	return "invalid JSON: " + e.error.Error()
}

func (e invalidJSONError) Unwrap() error {
	return e.error
}

func (e invalidJSONError) InvalidParameter() {}
Repository: moby/moby
File: daemon/start_windows.go (Go)

Code before:
package daemon

import (
	"github.com/containerd/containerd/v2/defaults"
	"github.com/docker/docker/daemon/config"
	"github.com/docker/docker/daemon/container"
)

func (daemon *Daemon) getLibcontainerdCreateOptions(daemonCfg *configStore, container *container.Container) (string, interface{}, error) {
	if container.HostConfig.Runtime == "" {
		if daemon.containerdClient == nil {
			return config.WindowsV1RuntimeName, nil, nil
		} else {
			return defaults.DefaultRuntime, nil, nil
		}
	}

	return container.HostConfig.Runtime, nil, nil
}


Review comment (suggestion):
Not sure this `else` branch is actually needed. Empty runtime should be handled by containerd itself.

Code after:
package daemon

import (
	"context"

	"github.com/containerd/containerd/v2/defaults"
	"github.com/moby/moby/v2/daemon/container"
)

func (daemon *Daemon) getLibcontainerdCreateOptions(daemonCfg *configStore, container *container.Container) (string, any, error) {
	if container.HostConfig.Runtime == "" {
		if daemonCfg.DefaultRuntime != "" {
			container.HostConfig.Runtime = daemonCfg.DefaultRuntime
		} else {
			container.HostConfig.Runtime = defaults.DefaultRuntime
		}

		container.CheckpointTo(context.WithoutCancel(context.TODO()), daemon.containersReplica)
	}

	return container.HostConfig.Runtime, nil, nil
}
Repository: moby/moby
File: api/types/container/nat_aliases.go (Go)

Code before:
package container

import "github.com/docker/go-connections/nat"

// HostPort is a string containing port number and protocol in the format "80/tcp"
//
// It is currently an alias for [nat.Port] but may become a concrete type in a future release.
type HostPort = nat.Port

// PortSet is a collection of structs indexed by [HostPort].
//
// It is currently an alias for [nat.PortSet] but may become a concrete type in a future release.
type PortSet = nat.PortSet

// PortBinding represents a binding between a Host IP address and a [HostPort].
//
// It is currently an alias for [nat.PortBinding] but may become a concrete type in a future release.
type PortBinding = nat.PortBinding

// PortMap is a collection of [PortBinding] indexed by [HostPort].
//
// It is currently an alias for [nat.PortMap] but may become a concrete type in a future release.
type PortMap = nat.PortMap


Review comment (suggestion):
`Port` was already taken as name; also not sure if we need to alias this to the `nat` type, which is a `string` with (I think) no methods or otherwise.

https://github.com/moby/moby/blob/981a878cf558d44d4aac2cd776fd9561f54076d0/vendor/github.com/docker/go-connections/nat/nat.go#L11-L26

Code after:
package container

import "github.com/docker/go-connections/nat"

// PortRangeProto is a string containing port number and protocol in the format "80/tcp",
// or a port range and protocol in the format "80-83/tcp".
//
// It is currently an alias for [nat.Port] but may become a concrete type in a future release.
type PortRangeProto = nat.Port

// PortSet is a collection of structs indexed by [HostPort].
//
// It is currently an alias for [nat.PortSet] but may become a concrete type in a future release.
type PortSet = nat.PortSet

// PortBinding represents a binding between a Host IP address and a [HostPort].
//
// It is currently an alias for [nat.PortBinding] but may become a concrete type in a future release.
type PortBinding = nat.PortBinding

// PortMap is a collection of [PortBinding] indexed by [HostPort].
//
// It is currently an alias for [nat.PortMap] but may become a concrete type in a future release.
type PortMap = nat.PortMap
Repository: moby/moby
File: daemon/libnetwork/network.go (Go)

Code before:
	}
	n = ep.network

	ep.processOptions(options...)

	for _, llIPNet := range ep.Iface().LinkLocalAddresses() {
		if !llIPNet.IP.IsLinkLocalUnicast() {
			return nil, types.InvalidParameterErrorf("invalid link local IP address: %v", llIPNet.IP)
		}
	}

	if opt, ok := ep.generic[netlabel.MacAddress]; ok {
		if mac, ok := opt.(net.HardwareAddr); ok {
			ep.iface.mac = mac
		}
	}

	ipam, capability, err := n.getController().getIPAMDriver(n.ipamType)
	if err != nil {
		return nil, err
	}

	if ep.ipamOptions == nil {
		ep.ipamOptions = make(map[string]string)
	}
	ep.ipamOptions[netlabel.EndpointName] = ep.name
	if capability.RequiresMACAddress {
		if ep.iface.mac == nil {
			ep.iface.mac = netutils.GenerateRandomMAC()
		}
		ep.ipamOptions[netlabel.MacAddress] = ep.iface.mac.String()
	}

	wantIPv6 := n.enableIPv6 && !ep.disableIPv6

	if err = ep.assignAddress(ipam, n.enableIPv4, wantIPv6); err != nil {
		return nil, err
	}
	defer func() {
		if err != nil {
			ep.releaseAddress()
		}
	}()

	if err = n.addEndpoint(ctx, ep); err != nil {
		return nil, err
	}
	defer func() {
		if err != nil {
			if e := ep.deleteEndpoint(false); e != nil {
				log.G(ctx).Warnf("cleaning up endpoint failed %s : %v", name, e)

Review comment (refactor):
Since the endpoint will at least have the endpoint name label going forwards, I think it is fine to move this to line 1202 where the endpoint is instantiated and remove the check here.

i.e.
```go
    ep := &Endpoint{name: name, ..., ipamOptions: map[string]string{netlabel.EndpointName: name}}
```

Code after:
		}
	}

	ipam, capability, err := n.getController().getIPAMDriver(n.ipamType)
	if err != nil {
		return nil, err
	}

	ep.ipamOptions = map[string]string{netlabel.EndpointName: name}
	if capability.RequiresMACAddress {
		if ep.iface.mac == nil {
			ep.iface.mac = netutils.GenerateRandomMAC()
		}
		ep.ipamOptions[netlabel.MacAddress] = ep.iface.mac.String()
	}

	wantIPv6 := n.enableIPv6 && !ep.disableIPv6

	if err = ep.assignAddress(ipam, n.enableIPv4, wantIPv6); err != nil {
		return nil, err
	}
	defer func() {
		if err != nil {
			ep.releaseAddress()
		}
	}()

	if err = n.addEndpoint(ctx, ep); err != nil {
		return nil, err
	}
	defer func() {
		if err != nil {
			if e := ep.deleteEndpoint(false); e != nil {
				log.G(ctx).Warnf("cleaning up endpoint failed %s : %v", name, e)
			}
		}
	}()

	// We should perform storeEndpoint call right after addEndpoint
	// in order to have iface properly configured
	if err = n.getController().storeEndpoint(ctx, ep); err != nil {
		return nil, err
	}
	defer func() {
		if err != nil {
			if e := n.getController().deleteStoredEndpoint(ep); e != nil {
				log.G(ctx).Warnf("error rolling back endpoint %s from store: %v", name, e)
			}
		}
	}()