fix the mystery crash. fuck im retarded

This commit is contained in:
Cyberes 2024-03-15 19:10:24 -06:00
parent c73d17a2ec
commit 115bd60ec5
1 changed files with 30 additions and 25 deletions

View File

@ -8,7 +8,6 @@ import (
"crazyfs/logging" "crazyfs/logging"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"path/filepath" "path/filepath"
"runtime/debug"
) )
var log *logrus.Logger var log *logrus.Logger
@ -33,27 +32,29 @@ type ResponseItem struct {
} }
func NewResponseItem(cacheItem *CacheItem.Item) *ResponseItem { func NewResponseItem(cacheItem *CacheItem.Item) *ResponseItem {
defer func() { // TODO: this should never happen and can probably be removed.
if r := recover(); r != nil { // Problem was linked to the scenario where an item was not found in the cache
copiedItem := &CacheItem.Item{ // so a new crawl was triggered but the `childItem` var was never updated.
Path: cacheItem.Path, //defer func() {
Name: cacheItem.Name, // if r := recover(); r != nil {
Size: cacheItem.Size, // copiedItem := &CacheItem.Item{
Extension: cacheItem.Extension, // Path: cacheItem.Path,
Modified: cacheItem.Modified, // Name: cacheItem.Name,
Mode: cacheItem.Mode, // Size: cacheItem.Size,
IsDir: cacheItem.IsDir, // Extension: cacheItem.Extension,
IsSymlink: cacheItem.IsSymlink, // Modified: cacheItem.Modified,
Cached: cacheItem.Cached, // Mode: cacheItem.Mode,
Children: nil, // IsDir: cacheItem.IsDir,
MimeType: cacheItem.MimeType, // IsSymlink: cacheItem.IsSymlink,
} // Cached: cacheItem.Cached,
// Children: nil,
// MimeType: cacheItem.MimeType,
// }
// log.Fatalf("Recovered from panic: %s - %+v - %s", r, copiedItem, debug.Stack())
// }
//}()
log.Fatalf("Recovered from panic: %s - %+v - %s", r, copiedItem, debug.Stack()) newResponseItem := &ResponseItem{
}
}()
item := &ResponseItem{
Path: cacheItem.Path, Path: cacheItem.Path,
Name: cacheItem.Name, Name: cacheItem.Name,
Size: cacheItem.Size, Size: cacheItem.Size,
@ -67,7 +68,7 @@ func NewResponseItem(cacheItem *CacheItem.Item) *ResponseItem {
Type: cacheItem.MimeType, Type: cacheItem.MimeType,
} }
// Grab the children from the cache and add them to this new item // Grab the children from the cache and add them to this new newResponseItem
if len(cacheItem.Children) > 0 { // avoid a null entry for the children key in the JSON if len(cacheItem.Children) > 0 { // avoid a null entry for the children key in the JSON
var children []*CacheItem.Item var children []*CacheItem.Item
for _, child := range cacheItem.Children { for _, child := range cacheItem.Children {
@ -89,6 +90,8 @@ func NewResponseItem(cacheItem *CacheItem.Item) *ResponseItem {
log.Debugf("NewResponseItem - CrawlNoRecursion - not found %s - likely broken symlink", child) log.Debugf("NewResponseItem - CrawlNoRecursion - not found %s - likely broken symlink", child)
continue continue
} }
// Update the `childItem` var with the newly cached item.
childItem = item
} }
if childItem != nil { if childItem != nil {
@ -107,11 +110,13 @@ func NewResponseItem(cacheItem *CacheItem.Item) *ResponseItem {
} }
children = append(children, copiedChildItem) children = append(children, copiedChildItem)
} else { } else {
log.Errorf(`NewResponseItem - copiedChildItem for "%s" was null! - %+v`, child, cacheItem) // This should never happen but we've had issues in the past so it's a safety check.
log.Errorf(`NewResponseItem - copiedChildItem for "%s" was null!`, child)
continue
} }
} }
item.Children = children newResponseItem.Children = children
} }
return item return newResponseItem
} }