Skip to content

internal/dinosql: Error on missing queries #180

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 1 commit into from
Dec 16, 2019
Merged
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
12 changes: 9 additions & 3 deletions internal/dinosql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ func ParseQueries(c core.Catalog, settings GenerateSettings, pkg PackageSettings
for _, stmt := range tree.Statements {
// line, col := location(source, stmt)
query, err := parseQuery(c, stmt, source)
if err == errUnsupportedStatementType {
continue
}
if err != nil {
merr.Add(filename, source, location(stmt), err)
continue
Expand All @@ -229,11 +232,12 @@ func ParseQueries(c core.Catalog, settings GenerateSettings, pkg PackageSettings
}
}
}

if len(q) == 0 {
return nil, fmt.Errorf("path %s contains no queries", pkg.Queries)
}
if len(merr.Errs) > 0 {
return nil, merr
}

return &Result{Catalog: c, Queries: q, Settings: settings}, nil
}

Expand Down Expand Up @@ -365,6 +369,8 @@ func validateCmd(n nodes.Node, name, cmd string) error {
return nil
}

var errUnsupportedStatementType = errors.New("parseQuery: unsupported statement type")

func parseQuery(c core.Catalog, stmt nodes.Node, source string) (*Query, error) {
if err := validateParamRef(stmt); err != nil {
return nil, err
Expand All @@ -382,7 +388,7 @@ func parseQuery(c core.Catalog, stmt nodes.Node, source string) (*Query, error)
}
case nodes.UpdateStmt:
default:
return nil, fmt.Errorf("parseQuery: unsupported statement type: %T", n)
return nil, errUnsupportedStatementType
}

rawSQL, err := pluckQuery(source, raw)
Expand Down