Read resources default value #199

Closed
opened 2025-12-30 01:22:03 +01:00 by adam · 1 comment
Owner

Originally created by @jjuliano on GitHub (Sep 3, 2024).

I have a template that reads an optional resource.

field: String? = read("env:STRING")

However, this causes an error when the resource is read because env:STRING needs to exist, so I added a default value.

field: String? = read("env:STRING") ?? "DEFAULT_STRING"

The code above still fails and exits when attempting to read the resource.

Originally created by @jjuliano on GitHub (Sep 3, 2024). I have a template that reads an optional resource. ` field: String? = read("env:STRING") ` However, this causes an error when the resource is read because `env:STRING` needs to exist, so I added a default value. ` field: String? = read("env:STRING") ?? "DEFAULT_STRING" ` The code above still fails and exits when attempting to read the resource.
adam closed this issue 2025-12-30 01:22:04 +01:00
Author
Owner

@shurshun commented on GitHub (Sep 3, 2024):

This one should work:
field: String? = read?("env:STRING") ?? "DEFAULT_STRING"

@shurshun commented on GitHub (Sep 3, 2024): This one should work: `field: String? = read?("env:STRING") ?? "DEFAULT_STRING"`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#199