{"record":{"id":"33173d130b338566","repo":"thanos-io/thanos","slug":"remove-existing-file","errorCode":null,"errorMessage":"remove existing file","messagePattern":"remove existing file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/indexheader/parallel_bucket.go","lineNumber":170,"sourceCode":"func newPartFile(filename string) (*partFile, error) {\n\tdir := filepath.Dir(filename)\n\tdf, err := fileutil.OpenDir(dir)\n\tif os.IsNotExist(err) {\n\t\tif err := os.MkdirAll(dir, os.ModePerm); err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"create temp dir\")\n\t\t}\n\t\tdf, err = fileutil.OpenDir(dir)\n\t}\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"open temp dir\")\n\t}\n\n\tif err := df.Sync(); err != nil {\n\t\treturn nil, errors.Wrap(err, \"sync dir\")\n\t}\n\n\tif err := os.RemoveAll(filename); err != nil {\n\t\treturn nil, errors.Wrap(err, \"remove existing file\")\n\t}\n\tf, err := os.OpenFile(filepath.Clean(filename), os.O_CREATE|os.O_RDWR, 0600)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"open temp file\")\n\t}\n\treturn &partFile{\n\t\tfile:       f,\n\t\tfileWriter: bufio.NewWriterSize(f, 32*1024),\n\t\tfileReader: bufio.NewReaderSize(f, 32*1024),\n\t}, nil\n}\n\nfunc (p *partFile) Close() error {\n\tif err := p.file.Close(); err != nil {\n\t\treturn err\n\t}\n\treturn os.Remove(p.file.Name())\n}","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/indexheader/parallel_bucket.go#L152-L188","documentation":"Wraps os.RemoveAll in newPartFile: a pre-existing part file at the target path could not be deleted before recreating it (permissions or filesystem error). Leftover files from a previous partial run are the usual cause.","triggerScenarios":"Thrown at pkg/block/indexheader/parallel_bucket.go:170 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check for processes holding the old part file open","Fix permissions on the temp dir","Remove the stale file manually if safe"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}