{"record":{"id":"49175e5657172c3f","repo":"shadow1ng/fscan","slug":"output-file-not-specified","errorCode":null,"errorMessage":"output file not specified","messagePattern":"output file not specified","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/output_api.go","lineNumber":39,"sourceCode":"// InitOutput 初始化输出系统\nfunc InitOutput() error {\n\tfv := GetFlagVars()\n\n\t// silent模式：初始化NDJSON stdout写入器（独立于文件输出）\n\tif fv.Silent {\n\t\tStdoutWriter = output.NewStdoutNDJSONWriter()\n\t}\n\n\t// 用户通过-no flag禁用保存时，跳过文件初始化避免不必要的资源开销\n\tif fv.DisableSave {\n\t\treturn nil\n\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}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/common/output_api.go#L21-L57","documentation":"Validation guard in InitOutput: file output is enabled (DisableSave is false) but the -o/output file flag (fv.Outputfile) is an empty string, so there is nowhere to write results. It fires before the format switch and means the user must either supply an output path or pass -no to disable saving.","triggerScenarios":"Calling InitOutput without setting the Outputfile field (e.g. missing -o/--output flag or config entry).","commonSituations":"Users forget the -o flag in CLI mode; config file omits the output-file key; code paths construct FlagValue programmatically and skip Outputfile.","solutions":["Set the output file flag (-o) or Outputfile field before InitOutput","Default to a known filename like result.txt when appropriate","Add pre-validation in the CLI/config layer"],"exampleFix":"// before\nerr := InitOutput(fv) // fv.Outputfile == \"\"\n// after\nif fv.Outputfile == \"\" { fv.Outputfile = \"result.txt\" }\nerr := InitOutput(fv)","handlingStrategy":"validation","validationCode":"if fv.Outputfile == \"\" {\n    return errors.New(\"output file required: use -o <file>\")\n}","typeGuard":null,"tryCatchPattern":"if err := InitOutput(fv); err != nil {\n    if strings.Contains(err.Error(), \"output file not specified\") {\n        fv.Outputfile = \"result.txt\"\n        err = InitOutput(fv)\n    }\n}","preventionTips":["Set default output file in CLI flag defaults","Validate FlagValue before InitOutput","Document the -o flag as required"],"tags":["configuration","validation","cli"],"backgroundTag":"missing-required-config-field","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"}