-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(os/gcfg): file event error #4400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Fixes #4400 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a file event monitoring error that prevents Go projects from starting when located on network-mapped drives in Windows 11. The fix converts the error from a fatal failure to a warning message, allowing the application to continue running without file monitoring.
- Wraps file event monitoring in a defer function to handle errors gracefully
- Changes error handling from returning nil to printing a warning message
- Adds fmt import for warning output
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
defer func() { | ||
_, err := gfsnotify.Add(filePath, func(event *gfsnotify.Event) { | ||
a.jsonMap.Remove(usedFileNameOrPath) | ||
}) | ||
if err != nil { | ||
fmt.Printf("[warn] %v: failed listen file event: %v\n", filePath, err) | ||
} | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using defer
here is incorrect. The deferred function will execute when the enclosing function returns, not immediately. This means the file monitoring setup is postponed until function exit, which defeats the purpose of setting up monitoring during configuration loading. Remove the defer wrapper and handle the error inline.
Copilot uses AI. Check for mistakes.
a.jsonMap.Remove(usedFileNameOrPath) | ||
}) | ||
if err != nil { | ||
fmt.Printf("[warn] %v: failed listen file event: %v\n", filePath, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct use of fmt.Printf
for logging bypasses the application's logging framework. Consider using the gf framework's logging utilities (like glog
) for consistent log formatting and level management throughout the application.
Copilot uses AI. Check for mistakes.
问题描述: Windows 11 文件夹映射的网络驱动器里面的go项目在启动的时候会因为系统没有映射磁盘的文件事件监听而报错,从而导致整个项目启动失败,目前我临时的修复是将该错误改为警告进行打印