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

Empty environment variable problem #193

Open
Pitometsu opened this issue Jan 14, 2021 · 10 comments
Open

Empty environment variable problem #193

Pitometsu opened this issue Jan 14, 2021 · 10 comments

Comments

@Pitometsu
Copy link

How to pass an environment variable which is set, but value is empty, and expected type is string (Text)? (shoul be encoded as ''value in yaml configuration)
Currently it interprets empty environment variable as a null (just empty space in yaml configuration, of Null type).

app: Could not convert to expected type: Error in $.field.name: parsing Text failed, expected String, but encountered Null
CallStack (from HasCallStack):
  error, called at src/Data/Yaml/Config.hs:199:19 in yaml-0.11.2.0-44sOdEiCtMxGtgOoTNcdTZ:Data.Yaml.Config
app: (exit 1): failed
@Pitometsu
Copy link
Author

Pitometsu commented Jan 14, 2021

workaround


fail:

field:
  name: _env:ENV

but this works:

field:
  name: _env:ENV:''

@snoyberg
Copy link
Owner

The comment in the code you link seems to describe the situation. It's interpreting whether to treat as a string or not based on the default value. And otherwise it parses the input as YAML, which for an empty string is in fact null I believe.

@Pitometsu
Copy link
Author

Pitometsu commented Jan 17, 2021

Can similar behavior for Text be added? Not sure about ByteString. Thank you for pointing to the comment.

@snoyberg
Copy link
Owner

I don't understand the request. This is working as designed. Please clarify what alternative implementation you'd like to see, "similar behavior" doesn't make sense in this context, at least to me.

@Pitometsu
Copy link
Author

Pitometsu commented Jan 17, 2021

I mean: e.g. read empty environment variable value for all IsString instances (or any custom inherited class instances) as a '' not null, not String only, to make it slightly more open for extension. Would that make sense?

@snoyberg
Copy link
Owner

That would break existing programs, which expect YAML parsing to occur.

@Pitometsu
Copy link
Author

Pitometsu commented Jan 17, 2021

Reasonable remark, that's sad. But there still can be added class IsString t => AsString t.
And doing so for all the AsString. And derived instance for Text (e.g. in distinct module that supposed to be imported explicitly to avoid breaking the exist behavior).

@Pitometsu
Copy link
Author

Wait a moment. Which cases will that brake? Currently the lib just generate a runtime error for null value, which is not instance of Text. It just expected that library will successfully parse the valid value of empty environment variable to appropriated value of Text type, as it intended to. I see no breaking changes required.

@snoyberg
Copy link
Owner

This is all too vague for me to follow. I can’t guarantee it will get merged, but at this point I think your best bet is opening a PR with the changes you want to see.

@sjshuck
Copy link

sjshuck commented May 4, 2022

set, but value is empty

read empty environment variable value

successfully parse the valid value of empty environment variable

This makes no sense on Windows because there is no difference between an unset environment variable and one set to the empty string, even at the C API level.

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

3 participants