diff --git a/cli/queryflags/flags.go b/cli/queryflags/flags.go index f1295f5d41..c358dca6c8 100644 --- a/cli/queryflags/flags.go +++ b/cli/queryflags/flags.go @@ -42,17 +42,23 @@ func (f *Flags) ParseSourcesAndInputs(paths []string) ([]string, ast.Seq, *parse // and appears to start with a from or yield operator. // Otherwise, consider it a file. query, sset, err := compiler.Parse(src, f.Includes...) - if err == nil { - if s, err := semantic.Analyze(context.Background(), query, data.NewSource(storage.NewLocalEngine(), nil), nil); err == nil { - if semantic.HasSource(s) { - return nil, query, sset, false, nil - } - if semantic.StartsWithYield(s) { - return nil, query, sset, true, nil - } + if err != nil { + return nil, nil, nil, false, singleArgError(src, err) + } + s, err := semantic.Analyze(context.Background(), query, data.NewSource(storage.NewLocalEngine(), nil), nil) + if err != nil { + if list, ok := err.(parser.ErrorList); ok { + list.SetSourceSet(sset) } + return nil, nil, nil, false, err + } + if semantic.HasSource(s) { + return nil, query, sset, false, nil + } + if semantic.StartsWithYield(s) { + return nil, query, sset, true, nil } - return nil, nil, nil, false, singleArgError(src, err) + return nil, nil, nil, false, singleArgError(src, nil) } } query, sset, err := parser.ParseZed(f.Includes, src) @@ -92,6 +98,8 @@ func singleArgError(src string, err error) error { for _, line := range strings.Split(list.Error(), "\n") { fmt.Fprintf(&b, "\n %s", line) } + } else if err == nil { + b.WriteString("\n - the argument is a valid Zed query but does not begin with a source (e.g., \"file input.zson\") or yield operator") } else { b.WriteString("\n - the argument did not parse as a valid Zed query") } diff --git a/cmd/zq/ztests/from-pool-error.yaml b/cmd/zq/ztests/from-pool-error.yaml index 3df958f054..b0a469f542 100644 --- a/cmd/zq/ztests/from-pool-error.yaml +++ b/cmd/zq/ztests/from-pool-error.yaml @@ -4,6 +4,6 @@ script: | outputs: - name: stderr data: | - zq: could not invoke zq with a single argument because: - - a file could not be found with the name "from ( pool a )" - - the argument did not parse as a valid Zed query + zq: "from pool" cannot be used without a lake at line 1, column 8: + from ( pool a ) + ~~~~~~ diff --git a/cmd/zq/ztests/no-files.yaml b/cmd/zq/ztests/no-files.yaml index bf2732049c..10087f35fb 100644 --- a/cmd/zq/ztests/no-files.yaml +++ b/cmd/zq/ztests/no-files.yaml @@ -8,4 +8,4 @@ outputs: data: | zq: could not invoke zq with a single argument because: - a file could not be found with the name "doesnotexist" - - the argument did not parse as a valid Zed query + - the argument is a valid Zed query but does not begin with a source (e.g., "file input.zson") or yield operator diff --git a/compiler/semantic/op.go b/compiler/semantic/op.go index 4d3dd571ee..155657c915 100644 --- a/compiler/semantic/op.go +++ b/compiler/semantic/op.go @@ -158,7 +158,7 @@ func (a *analyzer) semSource(source ast.Source) []dag.Op { } case *ast.Pool: if !a.source.IsLake() { - a.error(s, errors.New("from pool cannot be used without a lake")) + a.error(s, errors.New("\"from pool\" cannot be used without a lake")) return []dag.Op{badOp()} } return a.semPool(s) diff --git a/compiler/ztests/from-error.yaml b/compiler/ztests/from-error.yaml index ee31a22987..05e6be1aac 100644 --- a/compiler/ztests/from-error.yaml +++ b/compiler/ztests/from-error.yaml @@ -15,7 +15,7 @@ script: | outputs: - name: stderr data: | - from pool cannot be used without a lake at line 1, column 1: + "from pool" cannot be used without a lake at line 1, column 1: from p ~~~~~~ ===