{"record":{"id":"2399114f1da91591","repo":"golangci/golangci-lint","slug":"failed-to-init-hash-salt-w","errorCode":null,"errorMessage":"failed to init hash salt: %w","messagePattern":"failed to init hash salt: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/run.go","lineNumber":213,"sourceCode":"\n\tc.fileCache = fsutils.NewFileCache()\n\tc.lineCache = fsutils.NewLineCache(c.fileCache)\n\n\tsw := timeutils.NewStopwatch(\"pkgcache\", c.log.Child(logutils.DebugKeyStopwatch))\n\n\tpkgCache, err := cache.NewCache(sw, c.log.Child(logutils.DebugKeyPkgCache))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to build packages cache: %w\", err)\n\t}\n\n\tguard := load.NewGuard()\n\n\tpkgLoader := lint.NewPackageLoader(c.log.Child(logutils.DebugKeyLoader), c.cfg, args, c.goenv, guard)\n\n\tc.contextBuilder = lint.NewContextBuilder(c.cfg, pkgLoader, pkgCache, guard)\n\n\tif err = initHashSalt(c.log.Child(logutils.DebugKeyGoModSalt), c.buildInfo.Version, c.cfg); err != nil {\n\t\treturn fmt.Errorf(\"failed to init hash salt: %w\", err)\n\t}\n\n\tif ok := c.acquireFileLock(); !ok {\n\t\treturn errors.New(\"parallel golangci-lint is running\")\n\t}\n\n\treturn nil\n}\n\nfunc (c *runCommand) postRun(_ *cobra.Command, _ []string) {\n\tc.releaseFileLock()\n}\n\nfunc (c *runCommand) execute(_ *cobra.Command, _ []string) {\n\tneedTrackResources := logutils.IsVerbose() || c.opts.PrintResourcesUsage\n\n\ttrackResourcesEndCh := make(chan struct{})\n","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/run.go#L195-L231","documentation":"`initHashSalt` derives a salt from the go.mod hash to key the lint cache. If it fails — e.g. it cannot locate or read go.mod, or cannot compute the hash — the error is wrapped as `failed to init hash salt: %w`. This happens in run's `preRunE`, before any packages are loaded.","triggerScenarios":"Running golangci-lint where go.mod cannot be found/read (no module context, go.mod unreadable, or the file is malformed), causing the salt derivation to fail.","commonSituations":"Running the linter outside a Go module directory; go.mod deleted or corrupted; permission problems on go.mod; running against a GOPATH-style project with no module; symlink/checkout issues in CI leaving go.mod missing.","solutions":["Run golangci-lint from the module root where go.mod exists (or set the working directory correctly in CI).","Restore/repair go.mod (`git checkout go.mod`, or `go mod init` if missing).","Check that go.mod is readable by the current user.","Read the wrapped error after the message for the precise cause (file not found vs read error)."],"exampleFix":"# before (CI step runs from repo root, linter run in subdir)\n- run: golangci-lint run ./pkg/...\n# after\n- run: golangci-lint run ./pkg/...   # executed at module root containing go.mod\n  working-directory: ${{ github.workspace }}","handlingStrategy":"validation","validationCode":"// confirm go.mod exists and is readable at the working directory\nif _, err := os.Stat(\"go.mod\"); err != nil {\n    return fmt.Errorf(\"run golangci-lint from a module root: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := initHashSalt(log, version, cfg); err != nil {\n    return fmt.Errorf(\"failed to init hash salt: %w\", err) // usually go.mod missing/unreadable\n}","preventionTips":["Run golangci-lint from the module root containing go.mod.","Set working-directory correctly in CI jobs running in subdirectories.","Don't delete or corrupt go.mod; restore it with git checkout if broken.","Keep go.mod readable by the user executing the linter."],"tags":["go","cache","gomod","module"],"backgroundTag":"go-mod-not-found","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}