{"record":{"id":"b40ed7ac1f282006","repo":"iflytek/astron-agent","slug":"invalid-service-port-v","errorCode":null,"errorMessage":"invalid SERVICE_PORT: %v","messagePattern":"invalid SERVICE_PORT: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tenant/config/env_loader.go","lineNumber":45,"sourceCode":"\t\t{\"DATABASE_MAX_OPEN_CONNS\", l.setDatabaseMaxOpenConns},\n\t\t{\"DATABASE_MAX_IDLE_CONNS\", l.setDatabaseMaxIdleConns},\n\t\t{\"LOG_PATH\", l.setLogPath},\n\t}\n\n\tfor _, mapping := range mappings {\n\t\tif value := os.Getenv(mapping.envKey); value != \"\" {\n\t\t\tif err := mapping.setValue(cfg, value); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (l *EnvLoader) setServicePort(cfg *Config, value string) error {\n\tif n, err := fmt.Sscanf(value, \"%d\", &cfg.Server.Port); err != nil || n != 1 {\n\t\treturn fmt.Errorf(\"invalid SERVICE_PORT: %v\", err)\n\t}\n\treturn nil\n}\n\nfunc (l *EnvLoader) setServiceLocation(cfg *Config, value string) error {\n\tcfg.Server.Location = value\n\treturn nil\n}\n\nfunc (l *EnvLoader) setDatabaseDBType(cfg *Config, value string) error {\n\tcfg.DataBase.DBType = value\n\treturn nil\n}\n\nfunc (l *EnvLoader) setDatabaseUsername(cfg *Config, value string) error {\n\tcfg.DataBase.UserName = value\n\treturn nil\n}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/tenant/config/env_loader.go#L27-L63","documentation":"EnvLoader.setServicePort parses the SERVICE_PORT environment variable with fmt.Sscanf(\"%d\") when it is non-empty; this error is returned when the value cannot be parsed as an integer (Sscanf returns an error or parses zero fields). It is surfaced from EnvLoader.Load, which LoadConfig propagates, aborting startup. Note the wrapped error is often nil when n != 1 without err, so the message may end with '%!v(MISSING)'-style output for non-numeric input.","triggerScenarios":"SERVICE_PORT set to a non-numeric or partially numeric value such as \"8080px\", \"localhost:8080\", \"eight-thousand\", an empty-ish string like \"  \" (whitespace only), or \"\" — actually empty strings are skipped by Load, so any non-empty non-integer value triggers it.","commonSituations":"Typos in Compose/Helm values, quoting a port together with extra text, pasting 'PORT=8080' (with prefix) into the value, YAML coercion to string '8080\n' with invisible characters, or locale-formatted numbers.","solutions":["Set SERVICE_PORT to a bare integer (e.g. SERVICE_PORT=8080) and restart the service.","Print the actual value (`printenv SERVICE_PORT | cat -A`) to reveal hidden characters or extra text and clean it up in the deployment manifest.","If the value comes from Helm/Compose templating, check that the template interpolates to a plain number and isn't concatenating a hostname or protocol.","For robustness in code, prefer strconv.Atoi over fmt.Sscanf to get a clearer parse error message."],"exampleFix":"// before\nSERVICE_PORT=\"http://localhost:8080\"\n// after\nSERVICE_PORT=8080","handlingStrategy":"validation","validationCode":"if v := os.Getenv(\"SERVICE_PORT\"); v != \"\" {\n\tif _, err := strconv.Atoi(v); err != nil {\n\t\treturn fmt.Errorf(\"SERVICE_PORT must be a plain integer, got %q\", v)\n\t}\n}","typeGuard":null,"tryCatchPattern":"_, err := config.LoadConfig(path)\nif err != nil && strings.HasPrefix(err.Error(), \"invalid SERVICE_PORT\") {\n\tlog.Fatalf(\"SERVICE_PORT=%q is not an integer: %v\", os.Getenv(\"SERVICE_PORT\"), err)\n}","preventionTips":["Store ports as bare integers in manifests — no protocol/host prefixes or units","Quote YAML values that could be coerced unexpectedly and verify rendered output","Run `printenv SERVICE_PORT | cat -A` when debugging to reveal hidden characters","Validate env vars with strconv.Atoi in CI before deploying"],"tags":["configuration","env-var","parsing","go"],"backgroundTag":"invalid-env-var-value","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}