{"record":{"id":"dcbb057d9af34fdd","repo":"vxcontrol/pentagi","slug":"failed-to-list-resources-w","errorCode":null,"errorMessage":"failed to list resources: %w","messagePattern":"failed to list resources: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/server/services/resources.go","lineNumber":2061,"sourceCode":"\tif dirPath != \"\" {\n\t\tescaped := resources.EscapeLike(dirPath)\n\t\tif recursive {\n\t\t\tq = q.Where(\"path = ? OR path LIKE ?\", dirPath, escaped+\"/%\")\n\t\t} else {\n\t\t\tq = q.Where(\n\t\t\t\t\"(path = ? AND is_dir = true) OR (path LIKE ? AND path NOT LIKE ?)\",\n\t\t\t\tdirPath,\n\t\t\t\tescaped+\"/%\",\n\t\t\t\tescaped+\"/%/%\",\n\t\t\t)\n\t\t}\n\t} else if !recursive {\n\t\tq = q.Where(\"path NOT LIKE ?\", \"%/%\")\n\t}\n\n\tvar recs []models.UserResource\n\tif err := q.Find(&recs).Error; err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to list resources: %w\", err)\n\t}\n\treturn convertResources(recs), nil\n}\n\nfunc (s *ResourceService) resourceExists(uid uint64, vPath string) (bool, error) {\n\tvar count int64\n\terr := s.db.Model(&models.UserResource{}).\n\t\tWhere(\"user_id = ? AND path = ?\", uid, vPath).\n\t\tCount(&count).Error\n\treturn count > 0, err\n}\n\nfunc ensureResourceDirs(tx *gorm.DB, uid uint64, dirPath string, force bool) (\n\t[]models.UserResource,\n\t[]models.UserResource,\n\t[]string,\n\terror,\n) {","sourceCodeStart":2043,"sourceCodeEnd":2079,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/server/services/resources.go#L2043-L2079","documentation":"queryResources runs the listing query (with prefix and recursion filters) via GORM Find and wraps any failure with this message. The wrapped cause is the actual DB error; a returned list simply could not be fetched.","triggerScenarios":"GET /resources listing failing because of DB connectivity loss, context timeout on large tables, or a malformed LIKE/prefix filter interacting with schema issues — anything that makes q.Find error.","commonSituations":"Database under heavy load or restarted mid-request; expired DB credentials; listing very large resource sets timing out.","solutions":["Retry the listing after checking DB health","Check the wrapped %w cause in server logs for the root driver error","Verify DB credentials/DSN configuration","Add pagination/limit if the user has an enormous number of resources"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"entries, err := listResources(uid, prefix)\nif err != nil {\n    if isTransientDB(err) { // net timeout, bad connection\n        return retryWithBackoff(3, func() error { _, err = listResources(uid, prefix); return err })\n    }\n    return err\n}","preventionTips":["Monitor DB uptime/credentials; rotate DSN secrets before expiry","Add pagination for users with very large resource sets","Set sane statement timeouts and connection pool limits"],"tags":["gorm","database","list","resources"],"backgroundTag":"database-query-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}