fix: allow the context on env load to be canceled [IDE-1791]#564
fix: allow the context on env load to be canceled [IDE-1791]#564
Conversation
Plus other nice to have options can be passed.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
pkg/envvars/environment.go
Outdated
| logger *zerolog.Logger | ||
| } | ||
|
|
||
| type LoadConfiguredEnvironmentOptions func(opts *loadConfiguredEnvironmentOptions) |
There was a problem hiding this comment.
Hm, don't we need to export the loadConfiguredEnvironmentOptions struct? I wonder how external processes should work with the pointer to the struct?
There was a problem hiding this comment.
Ah, actually we don't need either exported, we only need the pre-defined WithBlah functions exported, as that is all the external callers should interact with.
Although in theory someone may want to create a slice of the WithBlah functions, but if someone does want to do something that peculiar, they can come it and change it to be exported.
|
/review |
pkg/envvars/environment.go
Outdated
| } | ||
| } | ||
|
|
||
| func WithCustomConfigFiles(customConfigFiles []string, workingDirectory string) LoadConfiguredEnvironmentOptions { |
There was a problem hiding this comment.
For ease of use:
- shouldn't the custom config files be just absolute paths?
There was a problem hiding this comment.
Is that not just more effort for the caller? They would need to join all the .snyk.env, .envrc, etc. with the working dir path before calling.
Hmm, as a best of both, I could rename this one to WithRelativeCustomConfigFiles and then do a second function that is just for absolute config files.
There was a problem hiding this comment.
Made it so you have to pass absolute paths, but I added a util function that converts relative paths to absolute paths to make life easier for the callers.
This comment has been minimized.
This comment has been minimized.
| // The Bash env PATH is appended to the existing PATH (as a fallback), any other new PATH read is prepended (preferential). | ||
| func LoadConfiguredEnvironmentWithOptions(opts ...LoadConfiguredEnvironmentOptions) { | ||
| options := loadConfiguredEnvironmentOptions{ | ||
| ctx: context.Background(), |
There was a problem hiding this comment.
I guess, this should be a context with timeout of e.g. 5s
There was a problem hiding this comment.
getEnvFromShell already puts a 5 second timeout on the context. But we could shift the timeout up to encompass the entirety of the loading env if that's better?
There was a problem hiding this comment.
I tried moving the timeout up, but then you have to decide if you want it before or after getting the mutex, so I decided in the end to leave it as it currently is with only the timeout in getEnvFromShell. A caller can always specify a timeout on the context they pass.
Now requires absolute paths. But I also added a util function to make paths absolute. Added an overall timeout for the entire `LoadConfiguredEnvironmentWithOptions` function.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It was clashing with the mutex locking. The caller can just provide a timeout on their context. Make logging more accurate.
PR Reviewer Guide 🔍
|
|
The LS PR is blocked, I do want to mark the other function as deprecated, so I will wait to merge this until then. |
Plus other nice to have options can be passed.
Needed for snyk/snyk-ls#1173