Skip to content
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

Raise error when template variable is unset #356

Open
jerkstorecaller opened this issue Jul 24, 2022 · 4 comments
Open

Raise error when template variable is unset #356

jerkstorecaller opened this issue Jul 24, 2022 · 4 comments

Comments

@jerkstorecaller
Copy link

jerkstorecaller commented Jul 24, 2022

I started from the recipe example and renamed image to image_name_ext4, but forgot to change the .image before the printf. End-result? The variable is set to WARNING_UNSET.

$ cat test.yaml
{{- $architecture := or .architecture "amd64" -}}
{{- $suite := or .suite "buster" -}}
{{- $type := or .type "min" -}}
{{- $image_name_ext4 := or .image (printf "WARNING_UNSET_%s_%s.ext4" $suite $architecture) -}}
architecture: {{ $architecture }}
actions:
  - action: run
    chroot: false
    description: Checking image name
    command: echo {{ $image_name_ext4 }}

$ debos --print-recipe --dry-run -t "image_name_ext4":"image_1.1.ext4" test.yaml
2022/07/23 14:34:30 Recipe '/home/user/dev/test.yaml':
2022/07/23 14:34:30 architecture: amd64
actions:
  - action: run
    chroot: false
    description: Checking image name
    command: echo WARNING_UNSET_buster_amd64.ext4
2022/07/23 14:34:30 ==== Recipe done (Dry run) ====

This syntax is confusing to me. I feel like image_name_ext4 should either be empty/unset because I set a different hidden variable called image to WARNING_UNSET, or throw an error.

@obbardc
Copy link
Member

obbardc commented Aug 9, 2023

@jerkstorecaller can you please move your nice to haves into new issues? Those two are indeed things which I'd like to add :-)

As for this issue, I wonder if really we should title it Raise error when template variable is unset ? Would that be a satisfying solution here?

@jerkstorecaller
Copy link
Author

Done!

#430
#431

For this issue, it's actually two issues in one (sorry I was just giving general feedback).

  1. Raise error when template variable is unset
  2. Warn or raise an error when syntax is invalid , eg writing }} at the end of a line instead of -}}. Silently dropping the line is the issue.

I can refactor this into 2 issues if you want.

@obbardc
Copy link
Member

obbardc commented Aug 14, 2023

That'd be great -please keep this issue for the unset variable warning

@jerkstorecaller
Copy link
Author

Done. New ticket: #432

Will now refactor this OP.

@jerkstorecaller jerkstorecaller changed the title yaml template syntax could use more idiot-proofing by raising errors Raise error when template variable is unset Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants