{"record":{"id":"5557d6e7676797b4","repo":"vxcontrol/pentagi","slug":"errtermlogsinvalidrequest","errorCode":"ErrTermlogsInvalidRequest","errorMessage":"group field not found","messagePattern":"group field not found","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"backend/pkg/server/services/termlogs.go","lineNumber":99,"sourceCode":"\t\t}\n\t} else if slices.Contains(privs, \"termlogs.view\") {\n\t\tscope = func(db *gorm.DB) *gorm.DB {\n\t\t\treturn db.\n\t\t\t\tJoins(\"INNER JOIN flows f ON f.id = flow_id\").\n\t\t\t\tWhere(\"f.user_id = ?\", uid)\n\t\t}\n\t} else {\n\t\tlogger.FromContext(c).Errorf(\"error filtering user role permissions: permission not found\")\n\t\tresponse.Error(c, response.ErrNotPermitted, nil)\n\t\treturn\n\t}\n\n\tquery.Init(\"termlogs\", termlogsSQLMappers)\n\n\tif query.Group != \"\" {\n\t\tif _, ok := termlogsSQLMappers[query.Group]; !ok {\n\t\t\tlogger.FromContext(c).Errorf(\"error finding termlogs grouped: group field not found\")\n\t\t\tresponse.Error(c, response.ErrTermlogsInvalidRequest, errors.New(\"group field not found\"))\n\t\t\treturn\n\t\t}\n\n\t\tvar respGrouped termlogsGrouped\n\t\tif respGrouped.Total, err = query.QueryGrouped(s.db, &respGrouped.Grouped, scope); err != nil {\n\t\t\tlogger.FromContext(c).WithError(err).Errorf(\"error finding termlogs grouped\")\n\t\t\tresponse.Error(c, response.ErrInternal, err)\n\t\t\treturn\n\t\t}\n\n\t\tresponse.Success(c, http.StatusOK, respGrouped)\n\t\treturn\n\t}\n\n\tif resp.Total, err = query.Query(s.db, &resp.TermLogs, scope); err != nil {\n\t\tlogger.FromContext(c).WithError(err).Errorf(\"error finding termlogs\")\n\t\tresponse.Error(c, response.ErrInternal, err)\n\t\treturn","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/server/services/termlogs.go#L81-L117","documentation":"GetTermlogs supports grouped terminal-log queries. The `group` query parameter must name a field in termlogsSQLMappers; otherwise the handler responds with ErrTermlogsInvalidRequest before executing the aggregation.","triggerScenarios":"GET /termlogs?group=<field> where <field> is not a key of termlogsSQLMappers, e.g. grouping by a container or command field that is not mapped as groupable.","commonSituations":"Terminal-log viewers offering a group-by dropdown built from table columns rather than the mapper allow-list; clients reusing group values from other entities; older API versions exposing more group fields than the current mappers.","solutions":["Use a group value defined in termlogsSQLMappers in backend/pkg/server/services/termlogs.go.","Remove the group parameter to get the flat listing.","Update the client's group-by options to the supported fields.","Extend termlogsSQLMappers if the field must become groupable."],"exampleFix":"// before\nGET /api/v1/termlogs?group=container_name\n// after\nGET /api/v1/termlogs?group=type","handlingStrategy":"validation","validationCode":"const TERMLOGS_GROUP_FIELDS = ['type', 'created_at']; // keys of termlogsSQLMappers\nif (group && !TERMLOGS_GROUP_FIELDS.includes(group)) {\n  throw new Error(`invalid group field for termlogs: ${group}`);\n}","typeGuard":"function isValidTermlogGroup(g) {\n  return typeof g === 'string' && TERMLOGS_GROUP_FIELDS.includes(g);\n}","tryCatchPattern":"try {\n  return await api.getTermlogs({ group });\n} catch (e) {\n  if (e.code === 'ErrTermlogsInvalidRequest' && e.message === 'group field not found') {\n    return await api.getTermlogs({});\n  }\n  throw e;\n}","preventionTips":["Build the group-by selector from termlogsSQLMappers keys, not raw table columns.","Validate group values before the request.","Avoid sharing group field lists across entities.","Retry ungrouped when this specific error is returned."],"tags":["rest-api","validation","query-params","http-400"],"backgroundTag":"invalid-group-field","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}