diff --git a/pkg/persistence/tweet_queries.go b/pkg/persistence/tweet_queries.go index 84f716c..81c78ed 100644 --- a/pkg/persistence/tweet_queries.go +++ b/pkg/persistence/tweet_queries.go @@ -132,7 +132,11 @@ func (p Profile) GetTweetById(id TweetID) (Tweet, error) { `, id) if err != nil { - return Tweet{}, fmt.Errorf("Error executing GetTweetByID(%d):\n %w", id, err) + if err == sql.ErrNoRows { + return Tweet{}, fmt.Errorf("GetTweetById %d: %w", id, ErrNotInDB) + } else { + panic(err) + } } t.Spaces = []Space{} diff --git a/pkg/persistence/tweet_queries_test.go b/pkg/persistence/tweet_queries_test.go index 0c4c440..6234b57 100644 --- a/pkg/persistence/tweet_queries_test.go +++ b/pkg/persistence/tweet_queries_test.go @@ -8,6 +8,7 @@ import ( "github.com/go-test/deep" + "gitlab.com/offline-twitter/twitter_offline_engine/pkg/persistence" "gitlab.com/offline-twitter/twitter_offline_engine/pkg/scraper" ) @@ -326,3 +327,12 @@ func TestCheckTweetContentDownloadNeeded(t *testing.T) { // Should no longer need a download assert.False(profile.CheckTweetContentDownloadNeeded(tweet)) } + +func TestLoadMissingTweet(t *testing.T) { + profile_path := "test_profiles/TestTweetQueries" + profile := create_or_load_profile(profile_path) + + _, err := profile.GetTweetById(scraper.TweetID(6234234)) // Random number + require.Error(t, err) + assert.ErrorIs(t, err, persistence.ErrNotInDB) +}