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.

Throw error when requiredEnvVars are missing

See original GitHub issue

👋 @JasonEtco thanks for providing this utility, it’s super helpful!

What are your thoughts on throwing an error (saying, e.g. GitHub Actions environment unavailable) when the required environment variables are missing? My thoughts are this would make it a little more explicit when the Actions environment isn’t set, and would allow me to decide how to proceed (should I abort, or try and do something useful).

https://github.com/JasonEtco/actions-toolkit/blob/eecccc314c1bdb9991a6d59549d03907296bb6f8/src/index.ts#L142-L167

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JasonEtcocommented, Mar 29, 2019

Oh by the by @swinton - this may or may not work for your use-case, but you can define what events your Action is designed to be triggered by, which would help prevent undefined events!

1reaction
JasonEtcocommented, Mar 29, 2019

@swinton 👋 I’m here to report that I reverted #41 in #70 😅 I discovered that some environment variables are not present in every event, so to depend on the existence of some but not all is as unreliable as none (that’s confusing but I think it’s correct). I also encountered some friction while using this in v2.0.0-beta.1 - this was expected, but still not a great experience.

I’m going to close this issue because after investigating it and trying it out, I don’t believe that the predictability is worth the friction, especially because actions-toolkit is a good way to start writing Actions, where newcomers to the platform aren’t familiar with the nuances of where the event.json lives, what env vars do what, etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In Javascript, how can I throw an error if an environmental ...
Helper function that throws if the environment variable doesn't exist: ... null)) { throw ("missing env var for " + name); } return...
Read more >
when variable is defined as system variable but not .env file ...
The 'Missing environment variable' error is thrown if any value from the ... config (to verify you populate all required env vars).
Read more >
envalid - npm
There are two functions that handle errors: env.onError (used when there are any missing required env vars or validation errors) and env.
Read more >
Force Ansible to throw out error when vars is missing in yml?
Is it possible to force Ansible when replacing the var in yml files, which is undefined, throw out an error instead silently replaced...
Read more >
Problems with Environment Variables
Error message = "Environment variable set to non-existent directory" ... If the name is missing from the list, the ONLY possibilities are :....
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