-
Notifications
You must be signed in to change notification settings - Fork 3
🔧 Fix file path and watcher handling for config and status files #2196
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,8 +31,8 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/natefinch/lumberjack/v3" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const configFileName = "./.config.json" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const statusMessagesFileName = "./ttbb-data/status-messages.json" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const configFileName = ".config.json" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const statusMessagesFileName = "ttbb-data/status-messages.json" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Admin Slash Command Constants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // const boostBotHomeGuild string = "766330702689992720" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1079,17 +1079,20 @@ func main() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Println("event:", event) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if event.Has(fsnotify.Write) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if event.Has(fsnotify.Write) || event.Has(fsnotify.Rename) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch event.Name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case configFileName: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Println("modified file:", event.Name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| err := config.ReadConfig(event.Name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Println(err.Error()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _ = config.ReadConfig(event.Name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if event.Has(fsnotify.Rename) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _ = watcher.Add(event.Name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case statusMessagesFileName: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Println("modified file:", event.Name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ei.LoadStatusMessages(event.Name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if event.Has(fsnotify.Rename) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _ = watcher.Add(event.Name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1088
to
+1094
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _ = watcher.Add(event.Name) | |
| } | |
| case statusMessagesFileName: | |
| log.Println("modified file:", event.Name) | |
| ei.LoadStatusMessages(event.Name) | |
| if event.Has(fsnotify.Rename) { | |
| _ = watcher.Add(event.Name) | |
| _ = watcher.Add(configFileName) | |
| } | |
| case statusMessagesFileName: | |
| log.Println("modified file:", event.Name) | |
| ei.LoadStatusMessages(event.Name) | |
| if event.Has(fsnotify.Rename) { | |
| _ = watcher.Add(statusMessagesFileName) |
Copilot
AI
Feb 14, 2026
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.
Similar to the config file handling, errors from watcher.Add are silently ignored after a rename event. If re-adding the watch fails, the status messages file will no longer be monitored for changes, and the application will continue running without detecting future updates to this file.
At minimum, log when watcher.Add fails so operators are aware that file watching has stopped working.
| _ = watcher.Add(event.Name) | |
| } | |
| case statusMessagesFileName: | |
| log.Println("modified file:", event.Name) | |
| ei.LoadStatusMessages(event.Name) | |
| if event.Has(fsnotify.Rename) { | |
| _ = watcher.Add(event.Name) | |
| if err := watcher.Add(event.Name); err != nil { | |
| log.Printf("failed to re-add watch for config file %q after rename: %v", event.Name, err) | |
| } | |
| } | |
| case statusMessagesFileName: | |
| log.Println("modified file:", event.Name) | |
| ei.LoadStatusMessages(event.Name) | |
| if event.Has(fsnotify.Rename) { | |
| if err := watcher.Add(event.Name); err != nil { | |
| log.Printf("failed to re-add watch for status messages file %q after rename: %v", event.Name, err) | |
| } |
Copilot
AI
Feb 14, 2026
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.
The same issue applies here as with the config file: when handling fsnotify.Rename events, event.Name refers to the old file path that may no longer exist after the rename. You should re-add the watch using statusMessagesFileName constant instead of event.Name to ensure the watcher is monitoring the correct file path after the rename operation completes.
| _ = watcher.Add(event.Name) | |
| _ = watcher.Add(statusMessagesFileName) |
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.
The error from
config.ReadConfig(event.Name)is now being silently ignored (changed from checking and logging to_ =), and the subsequentwatcher.Adderror is also ignored. This is problematic because:ReadConfigfails, the application will continue running with stale configuration, which could lead to unexpected behaviorwatcher.Addfails after a rename event, the file will no longer be watched, meaning future changes to the config file won't be detectedConsider either logging these errors or handling them appropriately. At minimum, log when ReadConfig fails so operators know the config reload didn't succeed.