{"record":{"id":"8f014a710af2adf2","repo":"yorukot/superfile","slug":"could-not-find-free-name-for-s-after-many-attempt","errorCode":null,"errorMessage":"could not find free name for %s after many attempts","messagePattern":"could not find free name for (.+?) after many attempts","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/function.go","lineNumber":93,"sourceCode":"\tcounter := 1\n\t//nolint:mnd // 3 = full match + 2 capture groups\n\tif match := suffixRegexp.FindStringSubmatch(name); len(match) == 3 {\n\t\tname = match[1] // base name without (N)\n\t\tif num, err := strconv.Atoi(match[2]); err == nil {\n\t\t\tcounter = num + 1 // start from next number\n\t\t}\n\t}\n\n\t// Find first available name\n\tfor i := counter; i < 10_000; i++ {\n\t\tnewName := fmt.Sprintf(\"%s(%d)%s\", name, i, ext)\n\t\tnewPath := filepath.Join(dir, newName)\n\t\tif _, err := os.Stat(newPath); os.IsNotExist(err) {\n\t\t\treturn newPath, nil\n\t\t}\n\t}\n\n\treturn \"\", fmt.Errorf(\"could not find free name for %s after many attempts\", destination)\n}\n\n// Count how many file in the directory\nfunc countFiles(dirPath string) (int, error) {\n\tcount := 0\n\n\terr := filepath.Walk(dirPath, func(_ string, info os.FileInfo, err error) error {\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif !info.IsDir() {\n\t\t\tcount++\n\t\t}\n\t\treturn nil\n\t})\n\n\treturn count, err\n}","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/function.go#L75-L111","documentation":"Error \"could not find free name for %s after many attempts\" thrown in yorukot/superfile.","triggerScenarios":"Thrown at src/internal/function.go:93 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}