Skip to content

Add additional config path error wrapping and index to embeds #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 21, 2019
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
2 changes: 1 addition & 1 deletion cli/cmd/lib_config_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func allConfigPaths(root string) []string {

func appNameFromConfig() (string, error) {
appRoot := mustAppRoot()
return userconfig.ReadAppName(filepath.Join(appRoot, "app.yaml"))
return userconfig.ReadAppName(filepath.Join(appRoot, "app.yaml"), "app.yaml")
}

func AppNameFromFlagOrConfig() (string, error) {
Expand Down
10 changes: 1 addition & 9 deletions pkg/api/context/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,18 @@ type Model struct {
}

type TrainingDataset struct {
userconfig.ResourceConfigFields
*ComputedResourceFields
Name string `json:"name"`
ModelName string `json:"model_name"`
TrainKey string `json:"train_key"`
EvalKey string `json:"eval_key"`
MetadataKey string `json:"metadata_key"`
}

func (trainingDataset *TrainingDataset) GetName() string {
return trainingDataset.Name
}

func (trainingDataset *TrainingDataset) GetResourceType() resource.Type {
return resource.TrainingDatasetType
}

func (trainingDataset *TrainingDataset) GetFilePath() string {
return ""
}

func (models Models) OneByID(id string) *Model {
for _, model := range models {
if model.ID == id {
Expand Down
13 changes: 3 additions & 10 deletions pkg/api/context/python_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,18 @@ package context

import (
"github.com/cortexlabs/cortex/pkg/api/resource"
"github.com/cortexlabs/cortex/pkg/api/userconfig"
)

type PythonPackages map[string]*PythonPackage

type PythonPackage struct {
Name string `json:"name"`
userconfig.ResourceConfigFields
*ComputedResourceFields
SrcKey string `json:"src_key"`
PackageKey string `json:"package_key"`
*ComputedResourceFields
}

func (pythonPackage *PythonPackage) GetName() string {
return pythonPackage.Name
}

func (pythonPackage *PythonPackage) GetResourceType() resource.Type {
return resource.PythonPackageType
}

func (pythonPackage *PythonPackage) GetFilePath() string {
return ""
}
18 changes: 18 additions & 0 deletions pkg/api/resource/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const (
ErrNameNotFound
ErrNameOrTypeNotFound
ErrInvalidType
ErrTemplateInTemplate
ErrEmbedInTemplate
)

var (
Expand All @@ -41,6 +43,8 @@ var (
"err_name_not_found",
"err_name_or_type_not_found",
"err_invalid_type",
"err_template_in_template",
"err_embed_in_template",
}
)

Expand Down Expand Up @@ -121,3 +125,17 @@ func ErrorUnknownKind(name string) error {
message: fmt.Sprintf("unknown kind %s", s.UserStr(name)),
}
}

func ErrorTemplateInTemplate() error {
return ResourceError{
Kind: ErrTemplateInTemplate,
message: "templates cannot be defined inside of templates",
}
}

func ErrorEmbedInTemplate() error {
return ResourceError{
Kind: ErrEmbedInTemplate,
message: "embeds cannot be defined inside of templates",
}
}
11 changes: 1 addition & 10 deletions pkg/api/userconfig/aggregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ import (
type Aggregates []*Aggregate

type Aggregate struct {
Name string `json:"name" yaml:"name"`
ResourceConfigFields
Aggregator string `json:"aggregator" yaml:"aggregator"`
Inputs *Inputs `json:"inputs" yaml:"inputs"`
Compute *SparkCompute `json:"compute" yaml:"compute"`
Tags Tags `json:"tags" yaml:"tags"`
FilePath string `json:"file_path" yaml:"-"`
}

var aggregateValidation = &cr.StructValidation{
Expand Down Expand Up @@ -69,18 +68,10 @@ func (aggregates Aggregates) Validate() error {
return nil
}

func (aggregate *Aggregate) GetName() string {
return aggregate.Name
}

func (aggregate *Aggregate) GetResourceType() resource.Type {
return resource.AggregateType
}

func (aggregate *Aggregate) GetFilePath() string {
return aggregate.FilePath
}

func (aggregates Aggregates) Names() []string {
names := make([]string, len(aggregates))
for i, aggregate := range aggregates {
Expand Down
11 changes: 1 addition & 10 deletions pkg/api/userconfig/aggregators.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ import (
type Aggregators []*Aggregator

type Aggregator struct {
Name string `json:"name" yaml:"name"`
ResourceConfigFields
Inputs *Inputs `json:"inputs" yaml:"inputs"`
OutputType interface{} `json:"output_type" yaml:"output_type"`
Path string `json:"path" yaml:"path"`
FilePath string `json:"file_path" yaml:"-"`
}

var aggregatorValidation = &cr.StructValidation{
Expand Down Expand Up @@ -84,18 +83,10 @@ func (aggregators Aggregators) Get(name string) *Aggregator {
return nil
}

func (aggregator *Aggregator) GetName() string {
return aggregator.Name
}

func (aggregator *Aggregator) GetResourceType() resource.Type {
return resource.AggregatorType
}

func (aggregator *Aggregator) GetFilePath() string {
return aggregator.FilePath
}

func (aggregators Aggregators) Names() []string {
names := make([]string, len(aggregators))
for i, aggregator := range aggregators {
Expand Down
11 changes: 1 addition & 10 deletions pkg/api/userconfig/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ import (
type APIs []*API

type API struct {
Name string `json:"name" yaml:"name"`
ResourceConfigFields
ModelName string `json:"model_name" yaml:"model_name"`
Compute *APICompute `json:"compute" yaml:"compute"`
Tags Tags `json:"tags" yaml:"tags"`
FilePath string `json:"file_path" yaml:"-"`
}

var apiValidation = &cr.StructValidation{
Expand Down Expand Up @@ -67,18 +66,10 @@ func (apis APIs) Validate() error {
return nil
}

func (api *API) GetName() string {
return api.Name
}

func (api *API) GetResourceType() resource.Type {
return resource.APIType
}

func (api *API) GetFilePath() string {
return api.FilePath
}

func (apis APIs) Names() []string {
names := make([]string, len(apis))
for i, api := range apis {
Expand Down
12 changes: 1 addition & 11 deletions pkg/api/userconfig/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ limitations under the License.
package userconfig

import (
"github.com/cortexlabs/cortex/pkg/api/resource"
cr "github.com/cortexlabs/cortex/pkg/utils/configreader"
)

type App struct {
Name string `json:"name" yaml:"name"`
FilePath string `json:"file_path" yaml:"-"`
Name string `json:"name" yaml:"name"`
}

var appValidation = &cr.StructValidation{
Expand All @@ -40,14 +38,6 @@ var appValidation = &cr.StructValidation{
},
}

func (app *App) GetName() string {
return app.Name
}

func (app *App) GetResourceType() resource.Type {
return resource.AppType
}

func (app *App) Validate() error {
return nil
}
2 changes: 1 addition & 1 deletion pkg/api/userconfig/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

type Column interface {
GetName() string
Resource
IsRaw() bool
}

Expand Down
Loading