Skip to content

Commit 66928e2

Browse files
slonopotamusolljanat
authored andcommitted
Fix error messages to follow Go conventions
https://go.dev/wiki/CodeReviewComments#error-strings > Error strings should not be capitalized (unless beginning with proper nouns or acronyms) or end with punctuation, since they are usually printed following other context.
1 parent 0b08b5b commit 66928e2

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

containerd/containerd.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func withResolver(creds CredentialsOpt) containerd.RemoteOpt {
9696
func (d *Driver) pullImage(imageName, imagePullTimeout string, auth *RegistryAuth) (containerd.Image, error) {
9797
pullTimeout, err := time.ParseDuration(imagePullTimeout)
9898
if err != nil {
99-
return nil, fmt.Errorf("Failed to parse image_pull_timeout: %v", err)
99+
return nil, fmt.Errorf("failed to parse image_pull_timeout: %v", err)
100100
}
101101

102102
ctxWithTimeout, cancel := context.WithTimeout(d.ctxContainerd, pullTimeout)
@@ -117,7 +117,7 @@ func (d *Driver) pullImage(imageName, imagePullTimeout string, auth *RegistryAut
117117

118118
func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskConfig) (containerd.Container, error) {
119119
if config.Command != "" && config.Entrypoint != nil {
120-
return nil, fmt.Errorf("Both command and entrypoint are set. Only one of them needs to be set.")
120+
return nil, fmt.Errorf("both command and entrypoint are set. Only one of them needs to be set")
121121
}
122122

123123
// Entrypoint or Command set by the user, to override entrypoint or cmd defined in the image.
@@ -146,7 +146,7 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
146146
}
147147

148148
if !d.config.AllowPrivileged && config.Privileged {
149-
return nil, fmt.Errorf("Running privileged jobs are not allowed. Set allow_privileged to true in plugin config to allow running privileged jobs.")
149+
return nil, fmt.Errorf("running privileged jobs are not allowed. Set allow_privileged to true in plugin config to allow running privileged jobs")
150150
}
151151

152152
// Enable privileged mode.
@@ -161,7 +161,7 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
161161

162162
if config.PidMode != "" {
163163
if strings.ToLower(config.PidMode) != "host" {
164-
return nil, fmt.Errorf("Invalid pid_mode. Set pid_mode=host to enable host pid namespace.")
164+
return nil, fmt.Errorf("invalid pid_mode. Set pid_mode=host to enable host pid namespace")
165165
} else {
166166
opts = append(opts, oci.WithHostNamespace(specs.PIDNamespace))
167167
}
@@ -171,7 +171,7 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
171171
if len(config.ShmSize) > 0 {
172172
shmBytes, err := units.RAMInBytes(config.ShmSize)
173173
if err != nil {
174-
return nil, fmt.Errorf("Error in setting shm_size: %v", err)
174+
return nil, fmt.Errorf("error in setting shm_size: %v", err)
175175
}
176176
opts = append(opts, oci.WithDevShmSize(shmBytes/1024))
177177
}
@@ -182,7 +182,7 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
182182
}
183183

184184
if !config.Seccomp && config.SeccompProfile != "" {
185-
return nil, fmt.Errorf("seccomp must be set to true, if using a custom seccomp_profile.")
185+
return nil, fmt.Errorf("seccomp must be set to true, if using a custom seccomp_profile")
186186
}
187187

188188
// Enable default (or custom) seccomp profile.
@@ -261,7 +261,7 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
261261
mounts := make([]specs.Mount, 0)
262262
for _, mount := range config.Mounts {
263263
if (mount.Type == "bind" || mount.Type == "volume") && len(mount.Options) <= 0 {
264-
return nil, fmt.Errorf("Options cannot be empty for mount type: %s. You need to atleast pass rbind and ro.", mount.Type)
264+
return nil, fmt.Errorf("options cannot be empty for mount type: %s. You need to atleast pass rbind and ro", mount.Type)
265265
}
266266

267267
// Allow paths relative to $NOMAD_TASK_DIR.

containerd/driver.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
455455
var err error
456456
containerConfig.Image, err = d.pullImage(driverConfig.Image, driverConfig.ImagePullTimeout, &driverConfig.Auth)
457457
if err != nil {
458-
return nil, nil, fmt.Errorf("Error in pulling image %s: %v", driverConfig.Image, err)
458+
return nil, nil, fmt.Errorf("error in pulling image %s: %v", driverConfig.Image, err)
459459
}
460460

461461
d.logger.Info(fmt.Sprintf("Successfully pulled %s image\n", containerConfig.Image.Name()))
@@ -493,13 +493,13 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
493493

494494
container, err := d.createContainer(&containerConfig, &driverConfig)
495495
if err != nil {
496-
return nil, nil, fmt.Errorf("Error in creating container: %v", err)
496+
return nil, nil, fmt.Errorf("error in creating container: %v", err)
497497
}
498498

499499
d.logger.Info(fmt.Sprintf("Successfully created container with name: %s\n", containerName))
500500
task, err := d.createTask(container, cfg.StdoutPath, cfg.StderrPath)
501501
if err != nil {
502-
return nil, nil, fmt.Errorf("Error in creating task: %v", err)
502+
return nil, nil, fmt.Errorf("error in creating task: %v", err)
503503
}
504504

505505
d.logger.Info(fmt.Sprintf("Successfully created task with ID: %s\n", task.ID()))
@@ -562,20 +562,20 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
562562

563563
container, err := d.loadContainer(taskState.ContainerName)
564564
if err != nil {
565-
return fmt.Errorf("Error in recovering container: %v", err)
565+
return fmt.Errorf("error in recovering container: %v", err)
566566
}
567567

568568
task, err := d.getTask(container, taskState.StdoutPath, taskState.StderrPath)
569569
if err != nil {
570-
return fmt.Errorf("Error in recovering task: %v", err)
570+
return fmt.Errorf("error in recovering task: %v", err)
571571
}
572572

573573
ctxWithTimeout, cancel := context.WithTimeout(d.ctxContainerd, 30*time.Second)
574574
defer cancel()
575575

576576
status, err := task.Status(ctxWithTimeout)
577577
if err != nil {
578-
return fmt.Errorf("Error in recovering task status: %v", err)
578+
return fmt.Errorf("error in recovering task status: %v", err)
579579
}
580580

581581
h := &taskHandle{
@@ -652,7 +652,7 @@ func (d *Driver) StopTask(taskID string, timeout time.Duration, signal string) e
652652
}
653653

654654
if err := handle.shutdown(d.ctxContainerd, timeout, syscall.SIGTERM); err != nil {
655-
return fmt.Errorf("Shutdown failed: %v", err)
655+
return fmt.Errorf("shutdown failed: %v", err)
656656
}
657657

658658
return nil
@@ -731,7 +731,7 @@ func (d *Driver) SignalTask(taskID string, signal string) error {
731731
// for a list of supported signals.
732732
sig, ok := signals.SignalLookup[signal]
733733
if !ok {
734-
return fmt.Errorf("Invalid signal: %s", signal)
734+
return fmt.Errorf("invalid signal: %s", signal)
735735
}
736736

737737
return handle.signal(d.ctxContainerd, sig)
@@ -751,5 +751,5 @@ func (d *Driver) ExecTaskStreaming(ctx context.Context, taskID string, opts *dri
751751
// This is an optional capability.
752752
func (d *Driver) ExecTask(taskID string, cmd []string, timeout time.Duration) (*drivers.ExecTaskResult, error) {
753753
// TODO: implement driver specific logic to execute commands in a task.
754-
return nil, fmt.Errorf("This driver does not support exec")
754+
return nil, fmt.Errorf("this driver does not support exec")
755755
}

containerd/handle.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (h *taskHandle) IsRunning(ctxContainerd context.Context) (bool, error) {
9292

9393
status, err := h.task.Status(ctxWithTimeout)
9494
if err != nil {
95-
return false, fmt.Errorf("Error in getting task status: %v", err)
95+
return false, fmt.Errorf("error in getting task status: %v", err)
9696
}
9797

9898
return (status.Status == containerd.Running), nil
@@ -148,7 +148,7 @@ func (h *taskHandle) exec(ctx, ctxContainerd context.Context, taskID string, opt
148148
h.logger.Error("Failed to resize terminal", "error", err)
149149
return
150150
}
151-
}
151+
}
152152
}
153153
}()
154154

0 commit comments

Comments
 (0)