Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/docker/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ const (
DefaultStopTimeout = 10 * time.Second
)

type ErrNoImage struct{}

func (e ErrNoImage) Error() string {
return "Function has no associated image. Has it been built?"
}

// Runner starts and stops functions as local containers.
type Runner struct {
verbose bool // Verbose logging
Expand Down Expand Up @@ -81,7 +87,7 @@ func (n *Runner) Run(ctx context.Context, f fn.Function, address string, startTi
port = choosePort(host, port, DefaultDialTimeout)

if f.Build.Image == "" {
return job, errors.New("Function has no associated image. Has it been built?")
return job, ErrNoImage{}
}
if c, _, err = NewClient(client.DefaultDockerHost); err != nil {
return job, errors.Wrap(err, "failed to create Docker API client")
Expand Down
8 changes: 4 additions & 4 deletions pkg/docker/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package docker_test

import (
"context"
"errors"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -48,9 +49,8 @@ func TestDockerRunImagelessError(t *testing.T) {
f := fn.NewFunctionWith(fn.Function{})

_, err := runner.Run(context.Background(), f, "", fn.DefaultStartTimeout)
// TODO: switch to typed error:
expectedErrorMessage := "Function has no associated image. Has it been built?"
if err == nil || err.Error() != expectedErrorMessage {
t.Fatalf("Expected error '%v', got '%v'", expectedErrorMessage, err)
var noImageErr docker.ErrNoImage
if !errors.As(err, &noImageErr) {
t.Fatalf("expected ErrNoImage, got %v", err)
}
}
Loading