{"record":{"id":"300812b018f1c017","repo":"lima-vm/lima","slug":"failed-to-extract-ssh-local-port-from-q-w","errorCode":null,"errorMessage":"failed to extract SSH local port from %#q: %w","messagePattern":"failed to extract SSH local port from %#q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/store/instance.go","lineNumber":95,"sourceCode":"\t\t} else {\n\t\t\tctx, cancel := context.WithTimeout(ctx, 3*time.Second)\n\t\t\tdefer cancel()\n\t\t\tinfo, err := haClient.Info(ctx)\n\t\t\tif err != nil {\n\t\t\t\tinst.Status = limatype.StatusBroken\n\t\t\t\tinst.Errors = append(inst.Errors, fmt.Errorf(\"failed to get Info from %#q: %w\", haSock, err))\n\t\t\t} else {\n\t\t\t\tinst.SSHLocalPort = info.SSHLocalPort\n\t\t\t\tinst.AutoStartedIdentifier = info.AutoStartedIdentifier\n\t\t\t}\n\t\t}\n\t}\n\tif inst.SSHLocalPort == 0 {\n\t\tsshConfigPath := filepath.Join(instDir, filenames.SSHConfig)\n\t\tif port, err := sshPortFromConfig(sshConfigPath); err == nil {\n\t\t\tinst.SSHLocalPort = port\n\t\t} else if !errors.Is(err, os.ErrNotExist) {\n\t\t\tinst.Errors = append(inst.Errors, fmt.Errorf(\"failed to extract SSH local port from %#q: %w\", sshConfigPath, err))\n\t\t}\n\t}\n\n\tinst.CPUs = *y.CPUs\n\tmemory, err := units.RAMInBytes(*y.Memory)\n\tif err == nil {\n\t\tinst.Memory = memory\n\t}\n\tdisk, err := units.RAMInBytes(*y.Disk)\n\tif err == nil {\n\t\tinst.Disk = disk\n\t}\n\tinst.AdditionalDisks = y.AdditionalDisks\n\tinst.Networks = y.Networks\n\n\t// 0 out values since not configurable on WSL2\n\tif inst.VMType == limatype.WSL2 {\n\t\tinst.Memory = 0","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/store/instance.go#L77-L113","documentation":"When the instance's SSHLocalPort is unknown (0), Inspect falls back to parsing the per-instance ssh config file (<instDir>/ssh.config) with sshPortFromConfig. If parsing fails for a reason other than the file not existing, the error is recorded on the instance without marking it broken.","triggerScenarios":"sshPortFromConfig returns a non-ErrNotExist error while parsing <instDir>/ssh.config: unreadable file (permissions), malformed content causing strconv.Atoi failure after a 'Port ' prefix (e.g. 'Port abc').","commonSituations":"User hand-edited ~/.lima/<inst>/ssh.config and typoed the port; partial instance directory restored from backup with truncated config; permission issues after copying instance dirs between users.","solutions":["Check ~/.lima/<inst>/ssh.config content and ensure it has a valid line 'Port <number>'","Fix file permissions (should be readable by the current user)","Delete the instance's ssh.config and restart the instance so Lima regenerates it","As a last resort re-create the instance from its template"],"exampleFix":"// before: hand-edited ssh.config\nPort abc\n// after\nPort 49153","handlingStrategy":"validation","validationCode":"data, err := os.ReadFile(filepath.Join(instDir, \"ssh.config\"))\nif err == nil && !regexp.MustCompile(`(?m)^Port \\d+$`).Match(data) {\n    // config lacks a valid Port line; fix before Inspect\n}","typeGuard":null,"tryCatchPattern":"inst, err := store.Inspect(ctx, instDir)\nif inst != nil {\n    for _, e := range inst.Errors {\n        if strings.Contains(e.Error(), \"failed to extract SSH local port\") {\n            // fall back to stored ssh port or prompt user to restart\n        }\n    }\n}","preventionTips":["Never hand-edit ~/.lima/<inst>/ssh.config; let Lima manage it","Back up whole instance directories, not partial files","Keep the 'Port <n>' format with a space, not a tab"],"tags":["lima","ssh","config-parsing"],"backgroundTag":"malformed-config-file","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}