{"record":{"id":"da1f0ebac07aad88","repo":"shadow1ng/fscan","slug":"invalid-output-format-s","errorCode":null,"errorMessage":"invalid output format: %s","messagePattern":"invalid output format: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/output_api.go","lineNumber":51,"sourceCode":"\t}\n\n\toutputFile := fv.Outputfile\n\toutputFormat := fv.OutputFormat\n\n\tif outputFile == \"\" {\n\t\treturn fmt.Errorf(\"output file not specified\")\n\t}\n\n\tvar format output.Format\n\tswitch outputFormat {\n\tcase \"txt\":\n\t\tformat = output.FormatTXT\n\tcase \"json\":\n\t\tformat = output.FormatJSON\n\tcase \"csv\":\n\t\tformat = output.FormatCSV\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid output format: %s\", outputFormat)\n\t}\n\n\t// 如果使用默认文件名但格式不是txt，自动修正扩展名\n\tif outputFile == \"result.txt\" && outputFormat != \"txt\" {\n\t\toutputFile = \"result.\" + outputFormat\n\t}\n\n\tconfig := output.DefaultManagerConfig(outputFile, format)\n\tmanager, err := output.NewManager(config)\n\tif err != nil {\n\t\treturn err\n\t}\n\tResultOutput = manager\n\treturn nil\n}\n\n// CloseOutput 关闭输出系统\nfunc CloseOutput() error {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/common/output_api.go#L33-L69","documentation":"Default-branch guard in InitOutput's format switch: fv.OutputFormat is not one of \"txt\", \"json\", or \"csv\", so no output.Format can be selected for the requested output file. The invalid format string is echoed so the user can correct the flag.","triggerScenarios":"Setting fv.OutputFormat to something like 'xml', 'JSON' (uppercase), 'yaml', or an empty string that survives default handling.","commonSituations":"Typo in config file; uppercase/lowercase mismatch; copying a format name from another tool; defaulting logic failed to set a format.","solutions":["Use one of: txt, json, csv (lowercase)","Normalize the format with strings.ToLower before InitOutput","Add autocomplete/validation in the CLI layer"],"exampleFix":"// before\nfv.OutputFormat = \"JSON\"\n// after\nfv.OutputFormat = strings.ToLower(\"JSON\") // \"json\"","handlingStrategy":"validation","validationCode":"switch strings.ToLower(fv.OutputFormat) {\ncase \"txt\", \"json\", \"csv\":\ndefault:\n    return fmt.Errorf(\"format must be txt|json|csv, got %q\", fv.OutputFormat)\n}","typeGuard":"func validFormat(s string) bool {\n    switch strings.ToLower(s) { case \"txt\", \"json\", \"csv\": return true }\n    return false\n}","tryCatchPattern":"if err := InitOutput(fv); err != nil {\n    if strings.Contains(err.Error(), \"invalid output format\") { log.Fatalf(\"%v\", err) }\n}","preventionTips":["Normalize format input with strings.ToLower","Restrict CLI flag choices to txt/json/csv","Validate config values at load time"],"tags":["validation","enum","configuration"],"backgroundTag":"invalid-enum-value","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}