kataras/iris · error

kitchen time: dest is nil

Error message

kitchen time: dest is nil

What it means

KitchenTime.UnmarshalJSON first checks that the receiver pointer t is non-nil before doing any decoding. If a nil *KitchenTime is passed, decoding cannot store the result anywhere, so this error is returned immediately.

Source

Thrown at x/jsonx/kitchen_time.go:54

		return KitchenTime{}, err
	}

	return KitchenTime(tt), nil
}

// ParseKitchenTime reads from "s" and returns the KitchenTime time.
func ParseKitchenTime(s string) (KitchenTime, error) {
	if s == "" || s == "null" {
		return KitchenTime{}, nil
	}

	return parseKitchenTime(s)
}

// UnmarshalJSON binds the json "data" to "t" with the `KitchenTimeLayout`.
func (t *KitchenTime) UnmarshalJSON(data []byte) error {
	if t == nil {
		return fmt.Errorf("kitchen time: dest is nil")
	}

	if isNull(data) {
		return nil
	}

	data = trimQuotes(data)

	if len(data) == 0 {
		return nil
	}

	tt, err := parseKitchenTime(string(data))
	if err != nil {
		return err
	}

	*t = KitchenTime(tt)

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Pass a non-nil *KitchenTime to json.Unmarshal (declare var v jsonx.KitchenTime; unmarshal into &v).
  2. Initialize pointer struct fields before decoding: field = new(jsonx.KitchenTime).
  3. Use a value receiver target (KitchenTime, not *KitchenTime) so &v is always non-nil.

Example fix

// before
var t *jsonx.KitchenTime
json.Unmarshal(data, t) // kitchen time: dest is nil
// after
var t jsonx.KitchenTime
json.Unmarshal(data, &t)
Defensive patterns

Strategy: type-guard

Validate before calling

func ensureDest(t *jsonx.KitchenTime) error {
	if t == nil {
		return errors.New("kitchen time destination must be non-nil")
	}
	return nil
}

Type guard

func nonNilKitchenTime(t *jsonx.KitchenTime) (*jsonx.KitchenTime, bool) {
	if t == nil {
		return new(jsonx.KitchenTime), false
	}
	return t, true
}

Try / catch

if err := json.Unmarshal(data, kt); err != nil {
	if strings.Contains(err.Error(), "dest is nil") {
		return fmt.Errorf("unmarshal target was nil; allocate before decoding: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling json.Unmarshal(data, (*jsonx.KitchenTime)(nil)), invoking UnmarshalJSON on a nil field pointer (e.g. a *KitchenTime struct field that was never allocated), or a custom unmarshaler passing nil through.

Common situations: Structs with *KitchenTime fields left nil before decoding into them; reflection-based code constructing nil receivers; forgetting to initialize the target variable.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/298d85cc5bd2c5bb. Report an issue: GitHub.