mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
Add static analyzer to discourage use of panic() (#15075)
* Implement static analysis to prevent panics * Add nopanic to nogo * Fix violations and add exclusions Fix violations and add exclusions for all * Changelog fragment * Use pass.Report instead of pass.Reportf * Remove strings.ToLower for checking init method name * Add exclusion for herumi init * Move api/client/beacon template function to init and its own file * Fix nopanic testcase
This commit is contained in:
@@ -75,6 +75,8 @@ func (s *SlotIntervalTicker) Done() {
|
||||
}
|
||||
|
||||
// NewSlotTicker starts and returns a new SlotTicker instance.
|
||||
// This method panics if genesis time is zero.
|
||||
// lint:nopanic -- Communicated panic in godoc commentary.
|
||||
func NewSlotTicker(genesisTime time.Time, secondsPerSlot uint64) *SlotTicker {
|
||||
if genesisTime.IsZero() {
|
||||
panic("zero genesis time")
|
||||
@@ -89,6 +91,8 @@ func NewSlotTicker(genesisTime time.Time, secondsPerSlot uint64) *SlotTicker {
|
||||
|
||||
// NewSlotTickerWithOffset starts and returns a SlotTicker instance that allows a offset of time from genesis,
|
||||
// entering a offset greater than secondsPerSlot is not allowed.
|
||||
// This method will panic if genesis time is zero or the offset is less than seconds per slot.
|
||||
// lint:nopanic -- Communicated panic in godoc commentary.
|
||||
func NewSlotTickerWithOffset(genesisTime time.Time, offset time.Duration, secondsPerSlot uint64) *SlotTicker {
|
||||
if genesisTime.Unix() == 0 {
|
||||
panic("zero genesis time")
|
||||
@@ -176,6 +180,8 @@ func (s *SlotIntervalTicker) startWithIntervals(
|
||||
// several offsets of time from genesis,
|
||||
// Caller is responsible to input the intervals in increasing order and none bigger or equal than
|
||||
// SecondsPerSlot
|
||||
// This method will panic if genesis time is zero, intervals is 0 length, or offsets are invalid.
|
||||
// lint:nopanic -- Communicated panic in godoc commentary.
|
||||
func NewSlotTickerWithIntervals(genesisTime time.Time, intervals []time.Duration) *SlotIntervalTicker {
|
||||
if genesisTime.Unix() == 0 {
|
||||
panic("zero genesis time")
|
||||
|
||||
@@ -126,7 +126,7 @@ func EpochStart(epoch primitives.Epoch) (primitives.Slot, error) {
|
||||
func UnsafeEpochStart(epoch primitives.Epoch) primitives.Slot {
|
||||
es, err := EpochStart(epoch)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic(err) // lint:nopanic -- Unsafe is implied and communicated in the godoc commentary.
|
||||
}
|
||||
return es
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user