shadow1ng/fscan · error
invalid output format: %s
Error message
invalid output format: %s
What it means
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.
Source
Thrown at common/output_api.go:51
}
outputFile := fv.Outputfile
outputFormat := fv.OutputFormat
if outputFile == "" {
return fmt.Errorf("output file not specified")
}
var format output.Format
switch outputFormat {
case "txt":
format = output.FormatTXT
case "json":
format = output.FormatJSON
case "csv":
format = output.FormatCSV
default:
return fmt.Errorf("invalid output format: %s", outputFormat)
}
// 如果使用默认文件名但格式不是txt,自动修正扩展名
if outputFile == "result.txt" && outputFormat != "txt" {
outputFile = "result." + outputFormat
}
config := output.DefaultManagerConfig(outputFile, format)
manager, err := output.NewManager(config)
if err != nil {
return err
}
ResultOutput = manager
return nil
}
// CloseOutput 关闭输出系统
func CloseOutput() error {View on GitHub (pinned to 95cc12e753)
Solutions
- Use one of: txt, json, csv (lowercase)
- Normalize the format with strings.ToLower before InitOutput
- Add autocomplete/validation in the CLI layer
Example fix
// before
fv.OutputFormat = "JSON"
// after
fv.OutputFormat = strings.ToLower("JSON") // "json" Defensive patterns
Strategy: validation
Validate before calling
switch strings.ToLower(fv.OutputFormat) {
case "txt", "json", "csv":
default:
return fmt.Errorf("format must be txt|json|csv, got %q", fv.OutputFormat)
} Type guard
func validFormat(s string) bool {
switch strings.ToLower(s) { case "txt", "json", "csv": return true }
return false
} Try / catch
if err := InitOutput(fv); err != nil {
if strings.Contains(err.Error(), "invalid output format") { log.Fatalf("%v", err) }
} Prevention
- Normalize format input with strings.ToLower
- Restrict CLI flag choices to txt/json/csv
- Validate config values at load time
When it happens
Trigger: Setting fv.OutputFormat to something like 'xml', 'JSON' (uppercase), 'yaml', or an empty string that survives default handling.
Common situations: Typo in config file; uppercase/lowercase mismatch; copying a format name from another tool; defaulting logic failed to set a format.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- output file not specified
- result cannot be nil
- result cannot be nil
- parser_cidr_failed: %w
- parser_ip_range_failed: %w
AI-assisted analysis of shadow1ng/fscan@95cc12e753 (2026-09-06).
Data as JSON: /api/errors/da1f0ebac07aad88.
Report an issue: GitHub.