{"record":{"id":"f2d59909646c9291","repo":"shadow1ng/fscan","slug":"unable-to-open-output-file-w","errorCode":null,"errorMessage":"Unable to open output file: %w","messagePattern":"Unable to open output file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/local/keylogger.go","lineNumber":173,"sourceCode":"\n\ttimestamp := time.Now().Format(\"2006-01-02 15:04:05\")\n\tentry := fmt.Sprintf(\"[%s] %s\", timestamp, key)\n\tp.keyBuffer = append(p.keyBuffer, entry)\n}\n\n// saveKeysToFile 保存键盘记录到文件\nfunc (p *KeyloggerPlugin) saveKeysToFile(outputFile string, session *common.ScanSession) error {\n\tp.bufferMutex.RLock()\n\tdefer p.bufferMutex.RUnlock()\n\n\tif len(p.keyBuffer) == 0 {\n\t\tsession.LogInfo(i18n.GetText(\"keylogger_no_input\"))\n\t\treturn nil\n\t}\n\n\tfile, err := os.OpenFile(outputFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", i18n.GetText(\"output_file_open_failed\"), err)\n\t}\n\tdefer func() { _ = file.Close() }()\n\n\t// 写入头部信息\n\theader := i18n.GetText(\"keylogger_log_header\") + \"\\n\"\n\theader += i18n.Tr(\"local_start_time\", time.Now().Format(\"2006-01-02 15:04:05\")) + \"\\n\"\n\theader += i18n.Tr(\"local_platform\", runtime.GOOS) + \"\\n\"\n\theader += i18n.Tr(\"keylogger_event_count\", len(p.keyBuffer)) + \"\\n\"\n\theader += \"========================\\n\\n\"\n\n\tif _, err := file.WriteString(header); err != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", i18n.GetText(\"keylogger_header_write_failed\"), err)\n\t}\n\n\t// 写入键盘记录\n\tfor _, entry := range p.keyBuffer {\n\t\tif _, err := file.WriteString(entry + \"\\n\"); err != nil {\n\t\t\treturn fmt.Errorf(\"%s: %w\", i18n.GetText(\"keylogger_entry_write_failed\"), err)","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/local/keylogger.go#L155-L191","documentation":"Raised in KeyloggerPlugin.saveKeysToFile when opening the output file for writing (O_TRUNC) fails — permissions, missing directory, or path error; the localized 'output_file_open_failed' message wraps the cause.","triggerScenarios":"Thrown at plugins/local/keylogger.go:173 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the output directory exists and is writable","Adjust file permissions or run with appropriate privileges","Point to a different output file path"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}