Better error handling will empty env

This commit is contained in:
Mike Farah 2021-01-11 14:38:53 +11:00
parent a0e1f65b20
commit 69386316f3
3 changed files with 7 additions and 4 deletions

View File

@ -1,4 +1,4 @@
Use the `documentIndex` operator to select nodes of a particular document. Use the `documentIndex` operator (or the `di` shorthand) to select nodes of a particular document.
## Retrieve a document index ## Retrieve a document index
Given a sample.yml file of: Given a sample.yml file of:
```yaml ```yaml

View File

@ -2,6 +2,7 @@ package yqlib
import ( import (
"container/list" "container/list"
"fmt"
"os" "os"
"strings" "strings"
@ -27,6 +28,8 @@ func EnvOperator(d *dataTreeNavigator, matchMap *list.List, pathNode *PathTreeNo
Tag: "!!str", Tag: "!!str",
Value: rawValue, Value: rawValue,
} }
} else if rawValue == "" {
return nil, fmt.Errorf("Value for env variable '%v' not provided in env()", envName)
} else { } else {
var dataBucket yaml.Node var dataBucket yaml.Node
decoder := yaml.NewDecoder(strings.NewReader(rawValue)) decoder := yaml.NewDecoder(strings.NewReader(rawValue))

View File

@ -63,10 +63,10 @@ var recursiveDescentOperatorScenarios = []expressionScenario{
}, },
}, },
{ {
description: "Recursively find nodes with keys", description: "Recursively find nodes with keys",
subdescription: "Note that this example has wrapped the expression in `[]` to show that there are two matches returned. You do not have to wrap in `[]` in your path expression.", subdescription: "Note that this example has wrapped the expression in `[]` to show that there are two matches returned. You do not have to wrap in `[]` in your path expression.",
document: `{a: {name: frog, b: {name: blog, age: 12}}}`, document: `{a: {name: frog, b: {name: blog, age: 12}}}`,
expression: `[.. | select(has("name"))]`, expression: `[.. | select(has("name"))]`,
expected: []string{ expected: []string{
"D0, P[a], (!!seq)::- {name: frog, b: {name: blog, age: 12}}\n- {name: blog, age: 12}\n", "D0, P[a], (!!seq)::- {name: frog, b: {name: blog, age: 12}}\n- {name: blog, age: 12}\n",
}, },