{"record":{"id":"0e3e3a03a3b925cc","repo":"Billionmail/BillionMail","slug":"unsupported-file-type-s","errorCode":null,"errorMessage":"unsupported file type: %s","messagePattern":"unsupported file type: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/internal/controller/contact/contact.go","lineNumber":53,"sourceCode":"\tMaxPageSize     = 100\n)\n\n// parseContactFile parses contact file content based on file type\nfunc parseContactFile(fileContent []byte, fileType string) ([]*entity.Contact, error) {\n\n\t// if txt format, split by line\n\tif fileType == \"txt\" {\n\t\treturn parseTXTFile(fileContent)\n\t}\n\t// CSV format\n\tif fileType == \"csv\" {\n\t\treturn parseCSVFile(fileContent)\n\t}\n\t// Excel format\n\tif fileType == \"excel\" {\n\t\treturn parseExcelFile(fileContent)\n\t}\n\treturn nil, fmt.Errorf(\"unsupported file type: %s\", fileType)\n}\n\n// parseTXTFile parses txt file content, one email per line\nfunc parseTXTFile(fileContent []byte) ([]*entity.Contact, error) {\n\t//fmt.Printf(\"parseTXTFile - Content length: %d bytes\\n\", len(fileContent))\n\t//fmt.Printf(\"parseTXTFile - Content as string: %s\\n\", string(fileContent))\n\n\tvar contacts []*entity.Contact\n\tlines := bytes.Split(fileContent, []byte(\"\\n\"))\n\n\tfor _, line := range lines {\n\t\t// remove whitespace characters\n\t\temail := strings.TrimSpace(string(line))\n\n\t\tif email == \"\" {\n\t\t\tcontinue\n\t\t}\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/controller/contact/contact.go#L35-L71","documentation":"parseContactFile dispatches file parsing by a file-type string: 'txt', 'csv', or 'excel'. When the provided fileType matches none of these, it returns this sentinel error instead of guessing a parser. It is an input-validation guard, not an I/O or data error.","triggerScenarios":"An ImportContacts-style request supplies a fileType other than exactly \"txt\", \"csv\", or \"excel\" — e.g. \"xlsx\", \"xls\", \"TXT\" (uppercase), \"vcard\", or an empty string from an unset form field.","commonSituations":"Frontend sends the raw file extension ('.csv') instead of the bare type ('csv'); client uses 'xlsx' while the backend only recognizes 'excel'; new file types added client-side before server support; case differences from browser-provided MIME-derived types.","solutions":["Normalize and map the fileType before calling: lower-case it and map 'xlsx'/'xls' -> 'excel', strip leading dots.","Fix the client to send one of the three supported values: txt, csv, excel.","Optionally extend parseContactFile with additional parsers (e.g. real xlsx via excelize) if a new format must be supported.","Log the offending value so the client can be corrected; the message already includes %s."],"exampleFix":"// before\nif fileType == \"excel\" {\n    return parseExcelFile(fileContent)\n}\nreturn nil, fmt.Errorf(\"unsupported file type: %s\", fileType)\n// after\nfileType = strings.ToLower(strings.TrimPrefix(strings.TrimSpace(fileType), \".\"))\nif fileType == \"xlsx\" || fileType == \"xls\" {\n    fileType = \"excel\"\n}\nswitch fileType {\ncase \"txt\":\n    return parseTXTFile(fileContent)\ncase \"csv\":\n    return parseCSVFile(fileContent)\ncase \"excel\":\n    return parseExcelFile(fileContent)\n}\nreturn nil, fmt.Errorf(\"unsupported file type: %s\", fileType)","handlingStrategy":"validation","validationCode":"var supportedTypes = map[string]bool{\"txt\": true, \"csv\": true, \"excel\": true}\nfunc isSupportedFileType(ft string) bool {\n    return supportedTypes[strings.ToLower(strings.TrimSpace(ft))]\n}\n// call before parsing:\n// if !isSupportedFileType(fileType) { reject request with 400 }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize fileType (lowercase, trim, strip extension dot) server-side before dispatch","Whitelist allowed types in the upload endpoint schema so invalid values are rejected earlier","Return a clear 400 listing allowed values: txt, csv, excel","Add a unit test for parseContactFile covering unknown and empty fileType"],"tags":["input-validation","file-upload","contact-import"],"backgroundTag":"unsupported-file-type","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}