{"record":{"id":"d232f5a4601693f8","repo":"moonD4rk/HackBrowserData","slug":"unsupported-format-s","errorCode":null,"errorMessage":"unsupported format: %s","messagePattern":"unsupported format: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/formatter.go","lineNumber":23,"sourceCode":"\t\"io\"\n)\n\n// formatter serializes rows to a writer. Unexported — only used by Writer.\ntype formatter interface {\n\tformat(w io.Writer, rows []row) error\n\text() string\n}\n\nfunc newFormatter(name string) (formatter, error) {\n\tswitch name {\n\tcase \"csv\":\n\t\treturn &csvFormatter{}, nil\n\tcase \"json\":\n\t\treturn &jsonFormatter{}, nil\n\tcase \"cookie-editor\":\n\t\treturn &cookieEditorFormatter{fallback: &jsonFormatter{}}, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported format: %s\", name)\n\t}\n}\n","sourceCodeStart":5,"sourceCodeEnd":26,"githubUrl":"https://github.com/moonD4rk/HackBrowserData/blob/0503d04d7a8d0379d060268a74f1b149e5a0aad5/output/formatter.go#L5-L26","documentation":"newFormatter maps a user-supplied output format name to a formatter implementation (csv, json, cookie-editor). Any other name is rejected at writer construction time, before any data is extracted or written. This is a fail-fast validation of the --format CLI/config value.","triggerScenarios":"NewWriter (via newFormatter) was called with a format name outside the supported set {csv, json, cookie-editor}, e.g. 'yaml', 'JSON' (case-sensitive), or an empty string.","commonSituations":"Typo in the CLI flag (--format jsn); wrong casing since the switch is case-sensitive; users assuming XML/YAML/HTML output exists; scripts passing a variable built from config that defaults to an unsupported value.","solutions":["Pass one of the exact supported names: csv, json, or cookie-editor (case-sensitive).","Normalize the input to lowercase before calling NewWriter: strings.ToLower(format).","Check the CLI help / NewWriter docs for the current supported format list.","If another format is genuinely needed, add a formatter case in output/formatter.go implementing the formatter interface."],"exampleFix":"// before\nw, err := output.NewWriter(dir, \"JSON\", nil) // unsupported\n// after\nw, err := output.NewWriter(dir, strings.ToLower(\"JSON\"), nil) // \"json\"","handlingStrategy":"validation","validationCode":"var supported = map[string]bool{\"csv\": true, \"json\": true, \"cookie-editor\": true}\nif !supported[format] {\n\treturn fmt.Errorf(\"format %q not supported; use csv, json, or cookie-editor\", format)\n}","typeGuard":"func isValidFormat(s string) bool {\n\tswitch s { case \"csv\", \"json\", \"cookie-editor\": return true }\n\treturn false\n}","tryCatchPattern":"w, err := output.NewWriter(dir, format, nil)\nif err != nil && strings.Contains(err.Error(), \"unsupported format\") {\n\tw, err = output.NewWriter(dir, \"json\", nil) // default fallback\n}","preventionTips":["Validate the --format flag with a whitelist before calling NewWriter.","Remember the switch is case-sensitive; lowercase user input.","Check CLI help for the supported formats list."],"tags":["cli","validation","output","format"],"backgroundTag":"invalid-enum-value","analyzedSha":"0503d04d7a8d0379d060268a74f1b149e5a0aad5","analyzedAt":"2026-09-06T13:38:28.707Z","contentChangedAt":"2026-09-06T13:38:28.707Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}