Skip to content

Critical: WriteFrame silently eats marshaling errors #22

Description

@metis-sprock

Description

WriteReplayFrame returns (0, error) on marshaling failure, but the calling WriteFrame function ignores the return value entirely. If frame serialization fails, the frame is silently missing from the output with no error propagated to the caller.

Evidence

File: pkg/codec/echoreplay.go:119-140

func WriteReplayFrame(w io.Writer, frame *ReplayFrame) (int, error) {
    data, err := json.Marshal(frame)
    if err != nil {
        return 0, err  // returns error...
    }
    // ...
}

func (w *Writer) WriteFrame(frame *ReplayFrame) error {
    WriteReplayFrame(w.writer, frame)  // ...but caller ignores it
    // ...
}

Impact

Failed serialization = missing frame, no error reported. If a frame contains data that can't be marshaled to JSON (e.g., NaN float values, circular references), it's silently dropped. The caller believes the write succeeded. This produces tape files with gaps that are indistinguishable from legitimate data.

Suggested Fix

Check and propagate the error:

func (w *Writer) WriteFrame(frame *ReplayFrame) error {
    if _, err := WriteReplayFrame(w.writer, frame); err != nil {
        return fmt.Errorf("writing replay frame: %w", err)
    }
    // ...
}

🤖 Filed by Metis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions