iflytek/astron-agent · error

update content is empty

Error message

update content is empty

What it means

buildUpdate assembles an UPDATE statement from a list of SqlOption column setters; when no options are supplied there are no SET columns, so it returns this error instead of generating invalid SQL (UPDATE ... with empty SET).

Solutions

  1. Guarantee at least one SET column is passed, e.g. always include update_time via an option.
  2. In the caller, check len(options)==0 before invoking the update and return a no-op or a validation error.
  3. If the update is dynamic, fall back to fetching the record first and skipping the query when nothing changed.
  4. Wrap the DAO call and map this error to a 400-style 'no fields to update' response.

Example fix

// before
err := dao.UpdateAppByID(ctx, appID, opts...) // opts may be empty
// after
if len(opts) == 0 {
    return fmt.Errorf("no fields to update for app %s", appID)
}
opts = append(opts, WithUpdateTime(time.Now()))
err := dao.UpdateAppByID(ctx, appID, opts...)
Defensive patterns

Strategy: validation

Validate before calling

if len(opts) == 0 {
    return fmt.Errorf("no update fields supplied")
}

Try / catch

err := dao.UpdateX(ctx, id, opts...)
if err != nil && err.Error() == "update content is empty" {
    return nil // treat as no-op, nothing changed
}

Prevention

When it happens

Trigger: Calling an Update* DAO method (via buildUpdateWithQuery or the anonymous wrapper) with zero SqlOption arguments, e.g. UpdateAppByID(ctx, id) with no WithColumn/WithXxx setters.

Common situations: Dynamic update code built the options slice conditionally and every field was unchanged/filtered out; a caller passed an empty map of column updates; a refactor dropped the option arguments.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/09f73eae25454468. Report an issue: GitHub.

Appendix: source

Thrown at core/tenant/internal/dao/base.go:33

	buffer.WriteString(querySql)
	params := make([]interface{}, 0, len(options))
	for index, option := range options {
		sqlStr, param := option()
		params = append(params, param...)
		if index == 0 {
			buffer.WriteString(" where ")
			buffer.WriteString(sqlStr)
			continue
		}
		buffer.WriteString(" and ")
		buffer.WriteString(sqlStr)
	}
	return buffer.String(), params
}

func buildUpdate(updateSql string, options ...SqlOption) (string, []interface{}, error) {
	if len(options) == 0 {
		return "", nil, fmt.Errorf("update content is empty")
	}
	var buffer bytes.Buffer
	params := make([]interface{}, 0, len(options))
	for index, option := range options {
		s, param := option()
		buffer.WriteString(s)
		params = append(params, param...)
		if index == len(options)-1 {
			continue
		}
		buffer.WriteString(",\n")
	}
	return fmt.Sprintf(updateSql, buffer.String()), params, nil
}

func buildUpdateWithQuery(updateSql string, whereSql []SqlOption, setSql ...SqlOption) (string, []interface{}, error) {
	finalSql, setParams, err := buildUpdate(updateSql, setSql...)
	if err != nil {

View on GitHub (pinned to 5e758547a8)