carvel-dev / carvel-dev/ytt

`or` does not test possibly-undefined data values

Open
#836 3 comments 0 reactions 1 assignee Claimed by @vmunishwar View on GitHub
carvel accepted discussion documentation
Dominant language
Go
Stars
1.9k
Forks
167
PR merge metrics
No merged PRs in 30d

Description

**What steps did you take:**

I wrote this snippet into a new file `xyz.yaml`:

```yaml
#@ load("@ytt:data", "data")

#@ foo = data.values.foo or "bar"
```

**What happened:**

When running `ytt -f xyz.yaml`, the following error is generated:

```
ytt: Error:
- struct has no .foo field or method
in
template.yaml:3 | #@ foo = data.values.foo or "bar"
```

**What did you expect:**

I expected templating to complete successfully and generate an empty YAML file, per the FAQ:

> # How do I provide a default for a data value when it may not be defined? [¶](https://carvel.dev/ytt/docs/v0.38.0/faq/#how-do-i-provide-a-default-for-a-data-value-when-it-may-not-be-defined)
>
> When a value may be null, you can use or to specify a default.
>
> ```yaml
> #@ data.values.foo or "bar"
> ```

~ https://carvel.dev/ytt/docs/v0.38.0/faq/#how-do-i-provide-a-default-for-a-data-value-when-it-may-not-be-defined

**Environment:**

- ytt version (use `ytt --version`): 0.45.1
- OS (e.g. from `/etc/os-release`): macOS (via `brew install`)

---
Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible"
👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help working on this issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.