Skip to content

Commit 4a2f79f

Browse files
committed
be more defensive when searching
1 parent 69868d2 commit 4a2f79f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

internal/core/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func AbraxasHandler(ctx context.Context, b *tg.Bot, update *tg.Update) (*tg.Send
334334
slog.Error("media search, nothing found, continuing")
335335
// continue...
336336
} else {
337-
slog.Error("error in db.SelectRandomMedia()", "err", err)
337+
slog.Error("error in db.SearchRandomMedia()", "err", err)
338338
return nil, err
339339
}
340340
} else {

internal/db/media.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package db
22

33
import (
44
"context"
5+
"database/sql"
56
"fmt"
67
"time"
78

@@ -213,6 +214,9 @@ func SearchRandomMedia(ctx context.Context, m *Media, term string) error {
213214
}
214215

215216
term = utils.CleanText(term)
217+
if len(term) == 0 {
218+
return sql.ErrNoRows
219+
}
216220
stringGid := fmt.Sprint(m.GID) // FTS tables are text by default
217221
return q.GetContext(ctx, m, term, stringGid, stringGid)
218222
}
@@ -235,6 +239,9 @@ func SearchMedia(ctx context.Context, gid int64, term string, offset int) ([]Med
235239
}
236240

237241
term = utils.CleanText(term)
242+
if len(term) == 0 {
243+
return results, nil
244+
}
238245
stringGid := fmt.Sprint(gid) // FTS tables are text by default
239246
return results, q.Select(&results, term, stringGid, offset)
240247
}

0 commit comments

Comments
 (0)