Skip to content

Commit

Permalink
Panic when a service is referenced that doesn't exist (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiburt authored and elliotchance committed Aug 19, 2019
1 parent a683aa0 commit c4be90e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions expression.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"fmt"
"github.com/elliotchance/pie/pie"
"go/ast"
"golang.org/x/tools/go/ast/astutil"
"regexp"
"strings"

"github.com/elliotchance/pie/pie"
"golang.org/x/tools/go/ast/astutil"
)

type Expression string
Expand Down Expand Up @@ -50,6 +51,10 @@ func (e Expression) performSubstitutions(file *File, services Services, fromArgs
return fmt.Sprintf("container.Get%s", i[1])
}

if _, existsService := services[i[1]]; !existsService {
panic(fmt.Sprintf("service does not exist: %s", i[1]))
}

if _, ok := services[i[1]].ContainerFieldType(services).(*ast.FuncType); ok {
return fmt.Sprintf("container.%s", i[1])
}
Expand Down
Empty file modified main.go
100644 → 100755
Empty file.

0 comments on commit c4be90e

Please sign in to comment.