Skip to content

Commit

Permalink
Dont show compilation errors until after codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Jul 5, 2018
1 parent 9f6ff0c commit cc78971
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion codegen/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (cfg *Config) models() (*ModelBuild, error) {
func (cfg *Config) bind() (*Build, error) {
namedTypes := cfg.buildNamedTypes()

prog, err := cfg.loadProgram(namedTypes, false)
prog, err := cfg.loadProgram(namedTypes, true)
if err != nil {
return nil, errors.Wrap(err, "loading failed")
}
Expand Down Expand Up @@ -122,6 +122,13 @@ func (cfg *Config) bind() (*Build, error) {
return b, nil
}

func (cfg *Config) validate() error {
namedTypes := cfg.buildNamedTypes()

_, err := cfg.loadProgram(namedTypes, false)
return err
}

func (cfg *Config) loadProgram(namedTypes NamedTypes, allowErrors bool) (*loader.Program, error) {
conf := loader.Config{}
if allowErrors {
Expand Down
5 changes: 5 additions & 0 deletions codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func Generate(cfg Config) error {
if err = write(cfg.ExecFilename, buf.Bytes()); err != nil {
return err
}

if err = cfg.validate(); err != nil {
return errors.Wrap(err, "validation failed")
}

return nil
}

Expand Down

0 comments on commit cc78971

Please sign in to comment.