Ma77Ball commented on code in PR #9663:
URL: https://github.com/apache/texera/pull/9663#discussion_r4674633172
##########
agent-service/src/config/env.ts:
##########
@@ -19,14 +19,31 @@
import { z } from "zod";
-const EnvSchema = z.object({
+/**
+ * A boolean flag read from an environment variable. `z.coerce.boolean()` is
+ * `Boolean(value)`, which reads any non-empty string, "false" and "0"
+ * included, as true. This accepts true/1 and false/0 in any case, treats an
+ * empty value as unset, and rejects anything else.
+ */
+const envFlag = z
+ .preprocess(
+ value => {
+ if (typeof value !== "string") return value;
+ const normalized = value.trim().toLowerCase();
+ return normalized === "" ? undefined : normalized;
+ },
+ z.enum(["true", "false", "1", "0"]).optional()
+ )
+ .transform(value => value === "true" || value === "1");
Review Comment:
Before this change `LOG_PRETTY=on` or `yes` turned pretty logging on; now
they make `EnvSchema.parse(process.env)` throw, so the whole agent service
fails to start over a log-format flag. Rejecting typos is good, but `on/off`
and `yes/no` are common enough spellings that accepting them seems kinder than
crashing. Your call; if you agree, the `rejects %p` case in `env.spec.ts` needs
`yes` and `off` moved to the on/off lists.
Suggested fix:
```suggestion
z.enum(["true", "false", "1", "0", "yes", "no", "on", "off"]).optional()
)
.transform(value => value === "true" || value === "1" || value === "yes"
|| value === "on");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]