{"record":{"id":"0b3636e62d45cb3a","repo":"vxcontrol/pentagi","slug":"invalid-msglogresultformat-s","errorCode":null,"errorMessage":"invalid MsglogResultFormat: %s","messagePattern":"invalid MsglogResultFormat: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/server/models/msglogs.go","lineNumber":70,"sourceCode":"const (\n\tMsglogResultFormatPlain    MsglogResultFormat = \"plain\"\n\tMsglogResultFormatMarkdown MsglogResultFormat = \"markdown\"\n\tMsglogResultFormatTerminal MsglogResultFormat = \"terminal\"\n)\n\nfunc (s MsglogResultFormat) String() string {\n\treturn string(s)\n}\n\n// Valid is function to control input/output data\nfunc (s MsglogResultFormat) Valid() error {\n\tswitch s {\n\tcase MsglogResultFormatPlain,\n\t\tMsglogResultFormatMarkdown,\n\t\tMsglogResultFormatTerminal:\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid MsglogResultFormat: %s\", s)\n\t}\n}\n\n// Validate is function to use callback to control input/output data\nfunc (s MsglogResultFormat) Validate(db *gorm.DB) {\n\tif err := s.Valid(); err != nil {\n\t\tdb.AddError(err)\n\t}\n}\n\n// Msglog is model to contain log record information from agents about their actions\n// nolint:lll\ntype Msglog struct {\n\tID           uint64             `form:\"id\" json:\"id\" validate:\"min=0,numeric\" gorm:\"type:BIGINT;NOT NULL;PRIMARY_KEY;AUTO_INCREMENT\"`\n\tType         MsglogType         `form:\"type\" json:\"type\" validate:\"valid,required\" gorm:\"type:MSGLOG_TYPE;NOT NULL\"`\n\tMessage      string             `form:\"message\" json:\"message\" validate:\"required\" gorm:\"type:TEXT;NOT NULL\"`\n\tThinking     string             `form:\"thinking\" json:\"thinking\" validate:\"omitempty\" gorm:\"type:TEXT;NULL\"`\n\tResult       string             `form:\"result\" json:\"result\" validate:\"omitempty\" gorm:\"type:TEXT;NOT NULL;default:''\"`","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/server/models/msglogs.go#L52-L88","documentation":"MsglogResultFormat specifies how a message log's result is rendered: plain, markdown, or terminal. MsglogResultFormat.Valid() rejects any other string with this error; the GORM Validate callback also applies it when writing Msglog rows, aborting the save.","triggerScenarios":"Setting Msglog.ResultFormat from a client payload with a format like 'md', 'text', or 'ansi'; copying a format string from another product; saving a Msglog whose result_format column holds a value not in the three-value whitelist.","commonSituations":"Frontend shorthand formats ('md' instead of 'markdown'); config or API clients sending an empty string (empty string is also invalid); data imported from older schemas where the field used different names; scripts defaulting the field to 'plain' with wrong casing ('Plain').","solutions":["Use one of the exact values plain, markdown, or terminal (constants MsglogResultFormatPlain/Markdown/Terminal).","Default the field explicitly to models.MsglogResultFormatPlain when the caller does not specify a format instead of leaving it empty.","Validate client input at the API boundary: reject/normalize unknown format strings before building the model.","If a new rendering format is needed, add the constant to msglogs.go, extend Valid(), and migrate the Postgres enum."],"exampleFix":"// before\nlog := models.Msglog{ResultFormat: models.MsglogResultFormat(\"md\")}\n// after\nlog := models.Msglog{ResultFormat: models.MsglogResultFormatMarkdown} // \"markdown\"","handlingStrategy":"validation","validationCode":"func isValidMsglogResultFormat(v string) bool {\n\tswitch models.MsglogResultFormat(v) {\n\tcase models.MsglogResultFormatPlain,\n\t\tmodels.MsglogResultFormatMarkdown,\n\t\tmodels.MsglogResultFormatTerminal:\n\t\treturn true\n\t}\n\treturn false\n}","typeGuard":"func asMsglogResultFormat(v string) (models.MsglogResultFormat, bool) {\n\tf := models.MsglogResultFormat(v)\n\treturn f, f.Valid() == nil\n}","tryCatchPattern":"if err := format.Valid(); err != nil {\n\tformat = models.MsglogResultFormatPlain // safe fallback\n}","preventionTips":["Default ResultFormat explicitly (plain) when callers omit it — the empty string is invalid.","Normalize client shorthand ('md' → 'markdown') at the API boundary.","Use the models.MsglogResultFormat* constants exclusively.","Validate the format in frontend zod schemas too so bad values never reach the API."],"tags":["go","enum-validation","gorm"],"backgroundTag":"invalid-enum-value","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}