question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

empty string should return empty object instead of undefined

See original GitHub issue

Is there any good reason why yaml.safeLoad("") returns undefined instead of {}?

It looks to me that emtpy string should match empty object. Also, an empty file say file.yml may be empty and loading it should return the emtpy object also.

Looks to me that undefined may refer to more than one semantics and may be ambiguos, say an error or whatever the safeLoad() method does inside that honestly I don’t care what it does in detail, but I care the “contract” of its use.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
perlpunkcommented, Jul 16, 2020

@puzrin sorry, my explanation was incorrect! I edited it. Hope it’s clearer now.

1reaction
puzrincommented, Jul 16, 2020

@perlpunk thank you! created #567

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should functions return null or an empty object? - Stack Overflow
An empty object implies data has been returned, whereas returning null clearly indicates that nothing has been returned. Additionally, returning ...
Read more >
3 Clever Ways to Return Empty Value Instead of Null From a ...
It is best practice to return empty values rather than null ones. Especially when you return a collection, enumerable, or an object, you...
Read more >
Is it better to return NULL or empty values from functions ...
An empty object implies data has been returned, whereas returning null clearly indicates that nothing has been returned. Additionally, returning ...
Read more >
Return Optional not null - Java Practices
you can usually simply return an empty object instead of null , and it will work fine, without special handling. In these cases,...
Read more >
String.IsNullOrEmpty(String) Method (System) - Microsoft Learn
You can use the IsNullOrWhiteSpace method to test whether a string is null , its value is String.Empty, or it consists only of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found