Skip to content

encoding/json: invert panic-recover capture type #23012

Closed
@dsnet

Description

@dsnet

The current logic in json/decode.go does the following:

if r := recover(); r != nil {
if _, ok := r.(runtime.Error); ok {
panic(r)
}
err = r.(error)
}

This captures any panics that aren't runtime.Error, which is arguably a wider range of panics than should be captured. For example, a panic in the reflect package gets masked away as an error.

The logic in decodeState.error should wrap the error before panicking to ensure the recover only captures errors originating from the json package:

// error aborts the decoding by panicking with err.
func (d *decodeState) error(err error) {
panic(d.addErrorContext(err))
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions