vxcontrol/pentagi · warning

ErrSearchlogsInvalidRequest

ErrSearchlogsInvalidRequest

Error message

group field not found

What it means

GetSearchlogs supports grouped aggregation of search logs. The `group` query parameter is validated against searchlogsSQLMappers; any value not present in that map is rejected with ErrSearchlogsInvalidRequest before the grouped SQL query executes.

Source

Thrown at backend/pkg/server/services/searchlogs.go:101

		}
	} else if slices.Contains(privs, "searchlogs.view") {
		scope = func(db *gorm.DB) *gorm.DB {
			return db.
				Joins("INNER JOIN flows f ON f.id = flow_id").
				Where("f.user_id = ?", uid)
		}
	} else {
		logger.FromContext(c).Errorf("error filtering user role permissions: permission not found")
		response.Error(c, response.ErrNotPermitted, nil)
		return
	}

	query.Init("searchlogs", searchlogsSQLMappers)

	if query.Group != "" {
		if _, ok := searchlogsSQLMappers[query.Group]; !ok {
			logger.FromContext(c).Errorf("error finding searchlogs grouped: group field not found")
			response.Error(c, response.ErrSearchlogsInvalidRequest, errors.New("group field not found"))
			return
		}

		var respGrouped searchlogsGrouped
		if respGrouped.Total, err = query.QueryGrouped(s.db, &respGrouped.Grouped, scope); err != nil {
			logger.FromContext(c).WithError(err).Errorf("error finding searchlogs grouped")
			response.Error(c, response.ErrInternal, err)
			return
		}

		response.Success(c, http.StatusOK, respGrouped)
		return
	}

	if resp.Total, err = query.Query(s.db, &resp.SearchLogs, scope); err != nil {
		logger.FromContext(c).WithError(err).Errorf("error finding searchlogs")
		response.Error(c, response.ErrInternal, err)
		return

View on GitHub (pinned to ea665308ba)

Solutions

  1. Pick a group value that exists in searchlogsSQLMappers in backend/pkg/server/services/searchlogs.go.
  2. Drop the group parameter for a flat (non-grouped) listing.
  3. If grouping by engine/another unmapped column is needed, extend searchlogsSQLMappers and redeploy.
  4. Constrain the UI's group dropdown to the documented groupable fields.

Example fix

// before
GET /api/v1/searchlogs?group=Engine
// after
GET /api/v1/searchlogs?group=engine
Defensive patterns

Strategy: validation

Validate before calling

const SEARCHLOGS_GROUP_FIELDS = ['engine', 'created_at']; // keys of searchlogsSQLMappers
if (group && !SEARCHLOGS_GROUP_FIELDS.includes(group)) {
  throw new Error(`invalid group field for searchlogs: ${group}`);
}

Type guard

function isValidSearchlogGroup(g) {
  return typeof g === 'string' && SEARCHLOGS_GROUP_FIELDS.includes(g);
}

Try / catch

try {
  return await api.getSearchlogs({ group });
} catch (e) {
  if (e.code === 'ErrSearchlogsInvalidRequest' && e.message === 'group field not found') {
    return await api.getSearchlogs({});
  }
  throw e;
}

Prevention

When it happens

Trigger: GET /searchlogs?group=<field> where <field> is not a key of searchlogsSQLMappers, e.g. grouping by 'engine' when only certain columns are mapped, or any misspelled/unmapped name.

Common situations: Analytics UIs letting users pick arbitrary columns to group by; API clients hardcoding a field name from an older backend version; copying group parameters between searchlogs and other entities whose mappers differ.

Related errors


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