juicedata/juicefs · error

failed to marshal footer: %w

Error message

failed to marshal footer: %w

What it means

BakFooter.Marshal serializes the footer's protobuf message before writing it to the backup stream. proto.Marshal failure (invalid message state, nil message, field exceeding limits) aborts footer writing with this wrapped error.

Source

Thrown at pkg/meta/backup.go:184

	if err := footer.Unmarshal(r); err != nil {
		return nil, err
	}
	if footer.Msg.Magic != BakMagic {
		return nil, fmt.Errorf("invalid magic number %d, expect %d", footer.Msg.Magic, BakMagic)
	}
	f.Footer = footer
	return footer, nil
}

type BakFooter struct {
	Msg *pb.Footer
	Len uint64
}

func (h *BakFooter) Marshal(w io.Writer) error {
	data, err := proto.Marshal(h.Msg)
	if err != nil {
		return fmt.Errorf("failed to marshal footer: %w", err)
	}

	if n, err := w.Write(data); err != nil && n != len(data) {
		return fmt.Errorf("failed to write footer data: err %w, write len %d, expect len %d", err, n, len(data))
	}

	h.Len = uint64(len(data))
	if n, err := w.Write(binary.BigEndian.AppendUint64(nil, h.Len)); err != nil && n != 8 {
		return fmt.Errorf("failed to write footer length: err %w, write len %d, expect len 8", err, n)
	}
	return nil
}

func (h *BakFooter) Unmarshal(r io.ReadSeeker) error {
	lenSize := int64(unsafe.Sizeof(h.Len))
	_, _ = r.Seek(-lenSize, io.SeekEnd)

	data := make([]byte, lenSize)

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Retry the dump; if it reproduces, capture the full log and report with the metadata engine type
  2. Check that segments marshalled successfully before the footer (earlier errors in the log)
  3. Use a matching JuiceFS version for dump and load
Defensive patterns

Strategy: retry

Try / catch

if err := dumpMetaV2(ctx, w); err != nil {
    if strings.Contains(err.Error(), "failed to marshal footer") {
        log.Printf("footer serialization failed; retry dump and report if persistent")
    }
    return err
}

Prevention

When it happens

Trigger: writeFooter calls BakFooter.Marshal when the accumulated Footer.Msg (segment infos, magic) cannot be protobuf-serialized — e.g. a nil Msg pointer or corrupt segment info accumulated during DumpMetaV2.

Common situations: Dumping a metadata engine that produced a footer with unserializable content; a bug where footer Msg was never initialized because all segments failed; extreme numbers of segment types pushing message over size limits.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/3b4101843fe87e3b. Report an issue: GitHub.