vxcontrol/pentagi · error

failed to list resources: %w

Error message

failed to list resources: %w

What it means

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.

Source

Thrown at backend/pkg/server/services/resources.go:2061

	if dirPath != "" {
		escaped := resources.EscapeLike(dirPath)
		if recursive {
			q = q.Where("path = ? OR path LIKE ?", dirPath, escaped+"/%")
		} else {
			q = q.Where(
				"(path = ? AND is_dir = true) OR (path LIKE ? AND path NOT LIKE ?)",
				dirPath,
				escaped+"/%",
				escaped+"/%/%",
			)
		}
	} else if !recursive {
		q = q.Where("path NOT LIKE ?", "%/%")
	}

	var recs []models.UserResource
	if err := q.Find(&recs).Error; err != nil {
		return nil, fmt.Errorf("failed to list resources: %w", err)
	}
	return convertResources(recs), nil
}

func (s *ResourceService) resourceExists(uid uint64, vPath string) (bool, error) {
	var count int64
	err := s.db.Model(&models.UserResource{}).
		Where("user_id = ? AND path = ?", uid, vPath).
		Count(&count).Error
	return count > 0, err
}

func ensureResourceDirs(tx *gorm.DB, uid uint64, dirPath string, force bool) (
	[]models.UserResource,
	[]models.UserResource,
	[]string,
	error,
) {

View on GitHub (pinned to ea665308ba)

Solutions

  1. Retry the listing after checking DB health
  2. Check the wrapped %w cause in server logs for the root driver error
  3. Verify DB credentials/DSN configuration
  4. Add pagination/limit if the user has an enormous number of resources
Defensive patterns

Strategy: retry

Try / catch

entries, err := listResources(uid, prefix)
if err != nil {
    if isTransientDB(err) { // net timeout, bad connection
        return retryWithBackoff(3, func() error { _, err = listResources(uid, prefix); return err })
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: Database under heavy load or restarted mid-request; expired DB credentials; listing very large resource sets timing out.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/dcbb057d9af34fdd. Report an issue: GitHub.