winglang/wing

Confusion around `util.env` and `util.tryEnv` in preflight vs inflight contexts

Open

#4.601 aberto em 19 de out. de 2023

Ver no GitHub
 (7 comments) (0 reactions) (0 assignees)TypeScript (214 forks)github user discovery
good first issue🎨 sdk🐶 dogfood

Métricas do repositório

Stars
 (5.385 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

The util.env and util.tryEnv utilities work differently in preflight and inflight contexts.

Given the following example:

MY_VAR=123 wing compile main.w

// main.w
bring cloud;
bring util;

log(util.env("MY_VAR")); // Logs 123
let MY_VAR = util.env("MY_VAR");

new cloud.Function(inflight () => {
  log(util.tryEnv("MY_VAR") ?? "<no value>"); // Logs <no value>
  log(MY_VAR); // Logs 123
});

The Cloud Function util.tryEnv is being translated into a lookup to process.env rather than use the host's environment variables. I find this behaviour confusing, maybe even unnecessary. Do we need to access environment variables in inflight functions? The only environment variables we can specify are when invoking the Wing CLI.

IMO, log(util.tryEnv("MY_VAR") ?? "<no value>"); should log 123 as well, with the actual inflight code being inlined as log("123" ?? "<no value>"); (it could even be simplified to log("123")).

Guia do colaborador