{"record":{"id":"d31c9871662bc014","repo":"golang/go","slug":"working-directory-q-is-not-in-either-goroot-q-o","errorCode":null,"errorMessage":"working directory %q is not in either GOROOT(%q) or GOPATH(%q)","messagePattern":"working directory %q is not in either GOROOT\\(%q\\) or GOPATH\\(%q\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"misc/ios/go_ios_exec.go","lineNumber":295,"sourceCode":"\t\t\treturn \"\", false, err\n\t\t}\n\t\treturn subdir, true, nil\n\t}\n\n\tfor _, p := range filepath.SplitList(build.Default.GOPATH) {\n\t\tpabs, err := filepath.EvalSymlinks(p)\n\t\tif err != nil {\n\t\t\treturn \"\", false, err\n\t\t}\n\t\tif !strings.HasPrefix(cwd, pabs) {\n\t\t\tcontinue\n\t\t}\n\t\tsubdir, err := filepath.Rel(pabs, cwd)\n\t\tif err == nil {\n\t\t\treturn subdir, false, nil\n\t\t}\n\t}\n\treturn \"\", false, fmt.Errorf(\n\t\t\"working directory %q is not in either GOROOT(%q) or GOPATH(%q)\",\n\t\tcwd,\n\t\truntime.GOROOT(),\n\t\tbuild.Default.GOPATH,\n\t)\n}\n\nfunc infoPlist(pkgpath string) string {\n\treturn `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n<key>CFBundleName</key><string>golang.gotest</string>\n<key>CFBundleSupportedPlatforms</key><array><string>iPhoneOS</string></array>\n<key>CFBundleExecutable</key><string>gotest</string>\n<key>CFBundleVersion</key><string>1.0</string>\n<key>CFBundleShortVersionString</key><string>1.0</string>\n<key>CFBundleIdentifier</key><string>` + bundleID + `</string>","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/misc/ios/go_ios_exec.go#L277-L313","documentation":"Returned by the package-path resolver in go_ios_exec (go_ios_exec.go:295) when the current working directory is not nested under either runtime.GOROOT() or build.Default.GOPATH. The wrapper needs to derive the package's import path (subdir relative to GOROOT/GOPATH) to build and install the test app correctly.","triggerScenarios":"Running go_ios_exec (i.e., `go test` with GOOS=ios) from a directory that is neither inside GOROOT/src nor inside any GOPATH workspace, in module-aware mode where the package path cannot be derived from the filesystem location.","commonSituations":"Module-mode project outside GOPATH (the most common modern setup) where the resolver's GOROOT/GOPATH heuristic does not apply; symlinks causing prefix checks to fail after EvalSymlinks; running from /tmp or a directory unrelated to the Go source tree.","solutions":["Run from within the package directory of a module-aware project; ensure go_ios_exec supports module mode (newer versions derive the path from `go list`).","If relying on GOPATH mode, place the project under $GOPATH/src/<importpath> and run from there.","Resolve symlinks so cwd evaluates under GOROOT/GOPATH.","Upgrade go_ios_exec / the Go toolchain to a version that resolves package paths via `go list` rather than GOROOT/GOPATH prefixing."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func cwdUnderGorootOrGopath() error {\n    cwd, _ := os.Getwd()\n    gr := runtime.GOROOT()\n    gp := build.Default.GOPATH\n    for _, p := range []string{gr, gp} {\n        if p == \"\" {\n            continue\n        }\n        pa, err := filepath.EvalSymlinks(p)\n        if err == nil && strings.HasPrefix(cwd, pa) {\n            return nil\n        }\n    }\n    return fmt.Errorf(\"cwd %q not under GOROOT/GOPATH\", cwd)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run go_ios_exec from inside a module package directory.","Upgrade to a Go version whose go_ios_exec resolves paths via `go list`.","For GOPATH-mode projects, place code under $GOPATH/src/<importpath>."],"tags":["ios","go-test","gopath","goroot","module-mode","path-resolution"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}