core: Env.getOrFail method proposal

Brief Description

Sometimes a certain environment variable is essential for running the app. It’d be good to be able to assert presence while getting the value.

This would greatly aid debugging of cross-environment apps. And prevent developers from forgetting to set env in production.

Sample Code

Env.getOrFail('FOO')

Would throw something like that, if no value is provided:

throw InvalidArgumentException.missingParameter('Env.get', 'FOO')

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

I also have a rule that Env should only be used in config files, to make sure they all get resolved at runtime. I think this is a good idea

What should the new method name be?

I proposed getOrFail, which is inline with the Lucid naming (e.g. findOrFail).

You proposed to use exists.

To me, exists appears misleading, because it makes it sound like it’d check for existence rather than return a value.