vxcontrol/pentagi · error
invalid MsglogResultFormat: %s
Error message
invalid MsglogResultFormat: %s
What it means
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.
Source
Thrown at backend/pkg/server/models/msglogs.go:70
const (
MsglogResultFormatPlain MsglogResultFormat = "plain"
MsglogResultFormatMarkdown MsglogResultFormat = "markdown"
MsglogResultFormatTerminal MsglogResultFormat = "terminal"
)
func (s MsglogResultFormat) String() string {
return string(s)
}
// Valid is function to control input/output data
func (s MsglogResultFormat) Valid() error {
switch s {
case MsglogResultFormatPlain,
MsglogResultFormatMarkdown,
MsglogResultFormatTerminal:
return nil
default:
return fmt.Errorf("invalid MsglogResultFormat: %s", s)
}
}
// Validate is function to use callback to control input/output data
func (s MsglogResultFormat) Validate(db *gorm.DB) {
if err := s.Valid(); err != nil {
db.AddError(err)
}
}
// Msglog is model to contain log record information from agents about their actions
// nolint:lll
type Msglog struct {
ID uint64 `form:"id" json:"id" validate:"min=0,numeric" gorm:"type:BIGINT;NOT NULL;PRIMARY_KEY;AUTO_INCREMENT"`
Type MsglogType `form:"type" json:"type" validate:"valid,required" gorm:"type:MSGLOG_TYPE;NOT NULL"`
Message string `form:"message" json:"message" validate:"required" gorm:"type:TEXT;NOT NULL"`
Thinking string `form:"thinking" json:"thinking" validate:"omitempty" gorm:"type:TEXT;NULL"`
Result string `form:"result" json:"result" validate:"omitempty" gorm:"type:TEXT;NOT NULL;default:''"`View on GitHub (pinned to ea665308ba)
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.
Example fix
// before
log := models.Msglog{ResultFormat: models.MsglogResultFormat("md")}
// after
log := models.Msglog{ResultFormat: models.MsglogResultFormatMarkdown} // "markdown" Defensive patterns
Strategy: validation
Validate before calling
func isValidMsglogResultFormat(v string) bool {
switch models.MsglogResultFormat(v) {
case models.MsglogResultFormatPlain,
models.MsglogResultFormatMarkdown,
models.MsglogResultFormatTerminal:
return true
}
return false
} Type guard
func asMsglogResultFormat(v string) (models.MsglogResultFormat, bool) {
f := models.MsglogResultFormat(v)
return f, f.Valid() == nil
} Try / catch
if err := format.Valid(); err != nil {
format = models.MsglogResultFormatPlain // safe fallback
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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').
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- invalid MsgchainType: %s
- invalid MsglogType: %s
- invalid PromptType: %s
- invalid SearchEngineType: %s
- invalid SubtaskStatus: %s
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/0b3636e62d45cb3a.
Report an issue: GitHub.