Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit a369718

Browse files
committed
feat(ringbuffer): Treat empty ringbuffer as error
1 parent 3bf21b8 commit a369718

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

storage/ringbuffer/adapter.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@ func (a *adapter) Write(app string, message string) error {
8888
func (a *adapter) Read(app string, lines int) ([]string, error) {
8989
rb, ok := a.ringBuffers[app]
9090
if ok {
91-
return rb.read(lines), nil
91+
data := rb.read(lines)
92+
if len(data) == 0 {
93+
return nil, fmt.Errorf("Could not find logs for '%s'. Ringbuffer existed for '%s', but returned no logs.", app, app)
94+
}
95+
return data, nil
9296
}
93-
return nil, fmt.Errorf("Could not find logs for '%s'", app)
97+
return nil, fmt.Errorf("Could not find logs for '%s'. No ringbuffer existed for '%s'.", app, app)
9498
}
9599

96100
// Destroy deletes stored logs for the specified application

storage/ringbuffer/adapter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestReadFromNonExistingApp(t *testing.T) {
1818
if messages != nil {
1919
t.Error("Expected no messages, but got some")
2020
}
21-
if err == nil || err.Error() != fmt.Sprintf("Could not find logs for '%s'", app) {
21+
if err == nil || err.Error() != fmt.Sprintf("Could not find logs for '%s'. No ringbuffer existed for '%s'.", app, app) {
2222
t.Error("Did not receive expected error message")
2323
}
2424
}

0 commit comments

Comments
 (0)