mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-02-03 02:50:03 -05:00
store: new error type (noElementsLeft)
This commit is contained in:
parent
0718452bf9
commit
04be09d5d3
@ -243,10 +243,10 @@ type EtcdIterator struct {
|
||||
keys []string
|
||||
}
|
||||
|
||||
// GetNext gets the next element.
|
||||
// GetNext returns the next element of the iterator.
|
||||
func (i *EtcdIterator) GetNext() (string, error) {
|
||||
if i.idx >= len(i.keys) {
|
||||
return "", fmt.Errorf("index out of range [%d] with length %d", i.idx, len(i.keys))
|
||||
return "", &NoElementsLeftError{idx: i.idx}
|
||||
}
|
||||
key := i.keys[i.idx]
|
||||
i.idx++
|
||||
|
@ -1,7 +1,6 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
@ -170,11 +169,11 @@ type StdIterator struct {
|
||||
// GetNext returns the next element of the iterator.
|
||||
func (i *StdIterator) GetNext() (string, error) {
|
||||
if i.idx >= len(i.keys) {
|
||||
return "", fmt.Errorf("index out of range [%d] with length %d", i.idx, len(i.keys))
|
||||
return "", &NoElementsLeftError{idx: i.idx}
|
||||
}
|
||||
val := i.keys[i.idx]
|
||||
key := i.keys[i.idx]
|
||||
i.idx++
|
||||
return val, nil
|
||||
return key, nil
|
||||
}
|
||||
|
||||
// HasNext returns true if there are elements left to get with GetNext().
|
||||
|
@ -53,3 +53,14 @@ type ValueUnsetError struct {
|
||||
func (s *ValueUnsetError) Error() string {
|
||||
return fmt.Sprintf("store: requested value not set: %s", s.requestedValue)
|
||||
}
|
||||
|
||||
// NoElementsLeftError occurs when trying to get an element from an interator that
|
||||
// doesn't have elements left.
|
||||
type NoElementsLeftError struct {
|
||||
idx int
|
||||
}
|
||||
|
||||
// Error implements the Error interface.
|
||||
func (n *NoElementsLeftError) Error() string {
|
||||
return fmt.Sprintf("index out of range [%d]", n.idx)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user