{"record":{"id":"3ba28bcf03ec2952","repo":"temporalio/temporal","slug":"env-config-zone-can-not-be-set-if-configfilepath","errorCode":null,"errorMessage":"env, config, zone can not be set if configFilePath is set","messagePattern":"env, config, zone can not be set if configFilePath is set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"temporal/server_options.go","lineNumber":109,"sourceCode":"\tif so.config == nil {\n\t\terr := so.loadConfig()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to load config: %w\", err)\n\t\t}\n\t}\n\n\terr := so.validateConfig()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"config validation error: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (so *serverOptions) loadConfig() error {\n\tif so.configFilePath != \"\" {\n\t\tif so.env != \"\" || so.configDir != \"\" || so.zone != \"\" {\n\t\t\treturn errors.New(\"env, config, zone can not be set if configFilePath is set\")\n\t\t}\n\t\tcfg, err := config.Load(\n\t\t\tconfig.WithConfigFile(so.configFilePath),\n\t\t)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not load config file: %w\", err)\n\t\t}\n\t\tso.config = cfg\n\t\treturn nil\n\t}\n\tcfg, err := config.Load(\n\t\tconfig.WithEnv(so.env),\n\t\tconfig.WithConfigDir(so.configDir),\n\t\tconfig.WithZone(so.zone),\n\t)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not load config file: %w\", err)\n\t}","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/temporal/server_options.go#L91-L127","documentation":"loadConfig refuses to combine configFilePath with env, configDir (\"config\"), or zone settings. Loading a single explicit file is mutually exclusive with directory/env/zone-based config resolution, so this guard prevents ambiguous configuration sources and returns this validation error from loadAndValidate.","triggerScenarios":"Calling server option loaders (NewServerOptions/NewConfig etc., or the CLI) with both a config file path and env/config-dir/zone set — e.g. ENVIRONMENT=prod TEMPORAL_CONFIG_DIR=... plus --config /path/to/config.yaml, or code setting so.configFilePath and so.env together.","commonSituations":"Container images with env-based config baked in, then a user mounts/passes an explicit config file; CLI invocations mixing --env flags with --config; scripts exporting TEMPORAL_ENV while also pointing at a file.","solutions":["Unset env/configDir/zone (clear TEMPORAL_ENV / TEMPORAL_CONFIG_DIR and --env/--zone flags) when using configFilePath","Or drop configFilePath and rely on env/configDir/zone resolution instead","In code, choose one mode: either config.WithConfigFile(...) or config.WithEnv/WithConfigDir/WithZone","Wrap config loading so conflicting sources are detected and reported with which flags collided"],"exampleFix":"// before\nopts := temporal.NewServerOptions(\n    temporal.WithConfigFilePath(\"/etc/temporal/config.yaml\"),\n    temporal.WithEnv(\"prod\"), // conflicts\n)\n// after\nopts := temporal.NewServerOptions(\n    temporal.WithConfigFilePath(\"/etc/temporal/config.yaml\"),\n)","handlingStrategy":"validation","validationCode":"func pickConfigSource(env, zone, configDir, configFilePath string) (string, error) {\n    var set []string\n    if env != \"\" { set = append(set, \"env\") }\n    if configDir != \"\" { set = append(set, \"configDir\") }\n    if zone != \"\" { set = append(set, \"zone\") }\n    if configFilePath != \"\" { set = append(set, \"configFilePath\") }\n    if configFilePath != \"\" && len(set) > 1 {\n        return \"\", fmt.Errorf(\"configFilePath cannot be combined with: %v\", set[:len(set)-1])\n    }\n    return configFilePath, nil\n}","typeGuard":null,"tryCatchPattern":"if err := so.loadAndValidate(); err != nil {\n    if strings.Contains(err.Error(), \"env, config, zone can not be set if configFilePath\") {\n        return fmt.Errorf(\"clear env/config-dir/zone flags or drop --config: %w\", err)\n    }\n    return err\n}","preventionTips":["In containers, decide on one config mechanism and document it; don't bake env vars AND mount a file","In CLI wrappers, mutually exclude --config with --env/--zone flags before invoking","Inspect the environment (TEMPORAL_ENV, TEMPORAL_CONFIG_DIR) before defaulting to configFilePath"],"tags":["temporal-server","config","cli","validation"],"backgroundTag":"conflicting-config-sources","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}