fix: lang.resolve_lang pulls os.getenv directly -- violates DAW architecture #8

Closed
opened 2026-05-25 20:45:03 +02:00 by michael · 2 comments
Owner

Problem

lang.resolve_lang calls os.getenv("LC_ALL") and os.getenv("LANG")
directly. This violates the DAW architecture principle:

Only main is responsible for the environment. Modules receive what
they need via parameters -- they never reach out to the environment
themselves.

This also makes the function untestable without mocking the OS.

Fix

Remove os.getenv calls from resolve_lang. The caller (main) reads
the environment and passes the lang/locale via ctx:

ctx.lang or ctx.user_locale must be set by main before calling resolve_lang.

If no locale is available, main passes a default -- not the module.

See also

## Problem `lang.resolve_lang` calls `os.getenv("LC_ALL")` and `os.getenv("LANG")` directly. This violates the DAW architecture principle: Only main is responsible for the environment. Modules receive what they need via parameters -- they never reach out to the environment themselves. This also makes the function untestable without mocking the OS. ## Fix Remove os.getenv calls from resolve_lang. The caller (main) reads the environment and passes the lang/locale via ctx: ctx.lang or ctx.user_locale must be set by main before calling resolve_lang. If no locale is available, main passes a default -- not the module. ## See also - DAW/daw-modul-berhtjan-core#7 (unprotected require in init.lua)
Author
Owner

Clarification: os.getenv belongs in sys.lua only. sys reads the environment and passes values to config or main. Modules receive lang/locale via ctx -- never via os.getenv directly.

Clarification: os.getenv belongs in sys.lua only. sys reads the environment and passes values to config or main. Modules receive lang/locale via ctx -- never via os.getenv directly.
Author
Owner

Final clarification: os.getenv belongs in bin/wrapper only. The wrapper reads the OS environment (including LANG/LC_ALL for language fallback) and builds the ctx before calling main. sys.lua provides the getenv wrapper function. Modules and config.lua never call os.getenv directly.

Final clarification: os.getenv belongs in bin/wrapper only. The wrapper reads the OS environment (including LANG/LC_ALL for language fallback) and builds the ctx before calling main. sys.lua provides the getenv wrapper function. Modules and config.lua never call os.getenv directly.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/daw-modul-berhtjan-core#8
No description provided.