{"record":{"id":"579ea1260d0594e5","repo":"hashicorp/nomad","slug":"malformed-port-map-q","errorCode":null,"errorMessage":"malformed port map: %q","messagePattern":"malformed port map: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/mock/driver.go","lineNumber":482,"sourceCode":"\t// Store last configs\n\td.lastMu.Lock()\n\td.lastDriverTaskConfig = cfg\n\td.lastTaskConfig = driverConfig\n\td.lastMu.Unlock()\n\n\tif driverConfig.StartErr != \"\" {\n\t\treturn nil, nil, structs.NewRecoverableError(errors.New(driverConfig.StartErr), driverConfig.StartErrRecoverable)\n\t}\n\n\t// Create the driver network\n\tnet := &drivers.DriverNetwork{\n\t\tIP:            driverConfig.DriverIP,\n\t\tAutoAdvertise: driverConfig.DriverAdvertise,\n\t}\n\tif raw := driverConfig.DriverPortMap; len(raw) > 0 {\n\t\tparts := strings.Split(raw, \":\")\n\t\tif len(parts) != 2 {\n\t\t\treturn nil, nil, fmt.Errorf(\"malformed port map: %q\", raw)\n\t\t}\n\t\tport, err := strconv.Atoi(parts[1])\n\t\tif err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"malformed port map: %q -- error: %v\", raw, err)\n\t\t}\n\t\tnet.PortMap = map[string]int{parts[0]: port}\n\t}\n\n\tkillCtx, killCancel := context.WithCancel(context.Background())\n\th := &taskHandle{\n\t\ttaskConfig:      cfg,\n\t\tcommand:         driverConfig.Command,\n\t\texecCommand:     driverConfig.ExecCommand,\n\t\tpluginExitAfter: driverConfig.pluginExitAfterDuration,\n\t\tkillAfter:       driverConfig.killAfterDuration,\n\t\tlogger:          d.logger.With(\"task_name\", cfg.Name),\n\t\twaitCh:          make(chan interface{}),\n\t\tkillCh:          killCtx.Done(),","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/mock/driver.go#L464-L500","documentation":"StartTask converts the mock driver's DriverPortMap string into a single-entry port map by splitting on \":\". If the string does not contain exactly one colon-separated pair (one label and one port), the port map is considered malformed and StartTask aborts.","triggerScenarios":"DriverPortMap set to a string without exactly one colon: e.g. \"web\" (no colon), \"web:8080:extra\" (too many segments), or an empty string that still passed the len(raw) > 0 check.","commonSituations":"Users copying Docker-style multi-mapping syntax \"8080:80,9090:90\" which this driver does not support; trailing colons like \"http:\"; accidentally quoting or spacing the value.","solutions":["Set DriverPortMap to a single \"label:port\" pair, e.g. \"http:8080\".","Remove extra mappings or extra colons; only one port mapping is supported.","Verify no whitespace or accidental characters split the value."],"exampleFix":"// before\nmap[string]interface{}{\"DriverPortMap\": \"http:8080,https:8443\"}\n// after\nmap[string]interface{}{\"DriverPortMap\": \"http:8080\"}","handlingStrategy":"validation","validationCode":"raw, _ := cfg[\"DriverPortMap\"].(string)\nparts := strings.Split(raw, \":\")\nif len(parts) != 2 {\n    return fmt.Errorf(\"DriverPortMap must be a single label:port pair, got %q\", raw)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use exactly one label:port pair for the mock driver's DriverPortMap.","Do not reuse Docker-style multi-mapping syntax with this driver."],"tags":["nomad","mock-driver","config","port-mapping"],"backgroundTag":"malformed-port-map","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}