Add warning for uncomputable increments

This commit is contained in:
arberkatellari
2023-05-18 11:05:51 -04:00
committed by Dan Christian Bogos
parent 7a0ff57a36
commit e17d952f9c
2 changed files with 5 additions and 0 deletions

View File

@@ -471,6 +471,10 @@ func (ts *TimeSpan) createIncrementsSlice() {
// because ts cost is rounded
//incrementCost := rate / rateUnit.Seconds() * rateIncrement.Seconds()
nbIncrements := int(ts.GetDuration() / rateIncrement)
if nbIncrements < 0 {
utils.Logger.Warning(fmt.Sprintf("error: <%s with %+v>, when creating increments slice, TimeSpan: %s", utils.ErrUncomputableIncrement, nbIncrements, utils.ToJSON(ts)))
return
}
if nbIncrements > config.CgrConfig().RalsCfg().MaxIncrements {
utils.Logger.Warning(fmt.Sprintf("error: <%s with %+v>, when creating increments slice, TimeSpan: %s", utils.ErrMaxIncrementsExceeded, nbIncrements, utils.ToJSON(ts)))
ts.Increments = make([]*Increment, 0)

View File

@@ -70,6 +70,7 @@ var (
ErrUnsupportedFormat = errors.New("UNSUPPORTED_FORMAT")
ErrNoDatabaseConn = errors.New("NO_DATABASE_CONNECTION")
ErrMaxIncrementsExceeded = errors.New("MAX_INCREMENTS_EXCEEDED")
ErrUncomputableIncrement = errors.New("UNCOMPUTABLE_INCREMENT")
ErrIndexOutOfBounds = errors.New("INDEX_OUT_OF_BOUNDS")
ErrWrongPath = errors.New("WRONG_PATH")
ErrServiceAlreadyRunning = fmt.Errorf("service already running")