{"record":{"id":"1560ccbd39aa1aed","repo":"fatedier/frp","slug":"local-port-new-key-in-section-error-v","errorCode":null,"errorMessage":"local_port new key in section error: %v","messagePattern":"local_port new key in section error: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/config/legacy/client.go","lineNumber":328,"sourceCode":"\n\tif len(localPorts) == 0 {\n\t\treturn fmt.Errorf(\"local_port and remote_port is necessary\")\n\t}\n\n\t// Templates\n\tprefix := strings.TrimSpace(strings.TrimPrefix(section.Name(), \"range:\"))\n\n\tfor i := range localPorts {\n\t\ttmpname := fmt.Sprintf(\"%s_%d\", prefix, i)\n\n\t\ttmpsection, err := f.NewSection(tmpname)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tcopySection(section, tmpsection)\n\t\tif _, err := tmpsection.NewKey(\"local_port\", fmt.Sprintf(\"%d\", localPorts[i])); err != nil {\n\t\t\treturn fmt.Errorf(\"local_port new key in section error: %v\", err)\n\t\t}\n\t\tif _, err := tmpsection.NewKey(\"remote_port\", fmt.Sprintf(\"%d\", remotePorts[i])); err != nil {\n\t\t\treturn fmt.Errorf(\"remote_port new key in section error: %v\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc copySection(source, target *ini.Section) {\n\tfor key, value := range source.KeysHash() {\n\t\t_, _ = target.NewKey(key, value)\n\t}\n}\n\n// GetDefaultClientConf returns a client configuration with default values.\n// Note: Some default values here will be set to empty and will be converted to them\n// new configuration through the 'Complete' function to set them as the default","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/fatedier/frp/blob/6c8a8d0a97d03b44e9528d30b30c70cb9d61b405/pkg/config/legacy/client.go#L310-L346","documentation":"While expanding a range section, frp creates a derived ini section per port (named prefix_0, prefix_1, ...) via copySection and then calls tmpsection.NewKey('local_port', ...). This error wraps a failure of that NewKey call on the local_port key. go-ini's NewKey fails mainly when the section is frozen or the key/value contains invalid characters (e.g. control bytes or NUL) — with normal configs it essentially never fails.","triggerScenarios":"A range section whose port values, after formatting, contain characters go-ini rejects in a key value, or an ini.File constructed in a frozen/immutable mode; a generated prefix_i section name that collides with an existing frozen section. All are edge cases outside normal file-driven usage.","commonSituations":"Programmatically building the ini.File with go-ini options that freeze sections; extremely unusual config content copied from binary output introducing control characters.","solutions":["Sanitize the range section's values — plain digits, commas, and dashes only","If manipulating configs programmatically, do not freeze sections before calling the loader","Recreate the [range:...] section from scratch rather than patching a corrupted file"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if !regexp.MustCompile(`^[0-9,\\- ]+$`).MatchString(localPortStr) {\n    return fmt.Errorf(\"local_port contains invalid characters: %q\", localPortStr)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict range values to digits, commas, and dashes","Do not feed frozen ini.File objects into the legacy loader","Recreate corrupted range sections instead of hand-patching"],"tags":["frp","config","ini","range-proxy","go-ini"],"backgroundTag":null,"analyzedSha":"6c8a8d0a97d03b44e9528d30b30c70cb9d61b405","analyzedAt":"2026-08-15T06:53:27.215Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}