Skip to content

Commit

Permalink
chore: remove github.com/pkg/errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
omegaatt36 committed May 16, 2024
1 parent 36a3d8b commit b5c3e26
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package app

import (
"context"
"errors"
"log"
"os"
"os/signal"
"runtime/debug"
"syscall"

"github.com/omegaatt36/instagramrobot/cliflag"
"github.com/pkg/errors"

"github.com/urfave/cli/v2"
)

Expand Down
6 changes: 3 additions & 3 deletions app/bot/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/omegaatt36/instagramrobot/appmodule/providers"
"github.com/omegaatt36/instagramrobot/appmodule/telegram"
"github.com/omegaatt36/instagramrobot/logging"
"github.com/pkg/errors"

"gopkg.in/telebot.v3"
)

Expand All @@ -30,7 +30,7 @@ func (*Controller) OnStart(c telebot.Context) error {
}

if err := c.Reply("Hello! I'm instagram keeper, post some instagram public post/reels to me."); err != nil {
return errors.Wrap(err, "Couldn't sent the start command response")
return fmt.Errorf("couldn't sent the start command response: %w", err)
}

return nil
Expand Down Expand Up @@ -96,7 +96,7 @@ func (x *Controller) processLinks(links []string, m *telebot.Message) error {
func (*Controller) replyError(c telebot.Context, text string) error {
_, err := c.Bot().Reply(c.Message(), fmt.Sprintf("⚠️ *Oops, ERROR!*\n\n`%v`", text), telebot.ModeMarkdown)
if err != nil {
return errors.Wrapf(err, "Couldn't reply the Error, chat_id: %d", c.Chat().ID)
return fmt.Errorf("couldn't reply the Error, chat_id: %d, err: %w", c.Chat().ID, err)
}

return nil
Expand Down
5 changes: 3 additions & 2 deletions app/bot/api/info.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package api

import (
"github.com/pkg/errors"
"fmt"

"gopkg.in/telebot.v3"
)

Expand All @@ -13,7 +14,7 @@ func HandlerStart(c telebot.Context) error {
}

if err := c.Reply("Hello! I'm instagram keeper, post some instagram public post/reels to me."); err != nil {
return errors.Wrap(err, "Couldn't sent the start command response")
return fmt.Errorf("couldn't sent the start command response: %w", err)
}

return nil
Expand Down
16 changes: 10 additions & 6 deletions appmodule/providers/link-processor.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package providers

import (
"fmt"
"net/url"

"github.com/omegaatt36/instagramrobot/appmodule/instagram"
"github.com/omegaatt36/instagramrobot/domain"
"github.com/pkg/errors"
)

// LinkProcessor is the implementation of LinkProcessor.
Expand All @@ -29,25 +29,29 @@ func (processor *LinkProcessor) ProcessLink(link string) error {

// Validate URL
if err != nil {
return errors.Wrapf(err, "I couldn't parse the [%v] link.", link)
return fmt.Errorf("I couldn't parse the [%v] link: %w", link, err)
}

// Validate HOST in the URL (only instagram.com is allowed)
if url.Host != "instagram.com" && url.Host != "www.instagram.com" {
return errors.Wrapf(ErrInvalidHost, "can only process links from [instagram.com] not [%s]", url.Host)
return fmt.Errorf("can only process links from [instagram.com] not [%s], %w", url.Host, ErrInvalidHost)
}

// Extract short code
shortCode, err := instagram.ExtractShortCodeFromLink(url.Path)
if err != nil {
return errors.Wrapf(err, "couldn't extract the short code from the link [%s]", link)
return fmt.Errorf("couldn't extract the short code from the link [%s]: %w", link, err)
}

// Process fetching the short code from Instagram
response, err := processor.InstagramFetcher.GetPostWithCode(shortCode)
if err != nil {
return errors.Wrapf(err, "couldn't fetch the post with short code [%s]", shortCode)
return fmt.Errorf("couldn't fetch the post with short code [%s]: %w", shortCode, err)
}

return errors.Wrapf(processor.MediaSender.Send(&response), "couldn't send the media with short code [%s]", shortCode)
if err := processor.MediaSender.Send(&response); err != nil {
return fmt.Errorf("couldn't send the media with short code [%s], %w", shortCode, err)
}

return nil
}
9 changes: 5 additions & 4 deletions appmodule/telegram/media-sender.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package telegram

import (
"fmt"

"github.com/omegaatt36/instagramrobot/domain"
"github.com/omegaatt36/instagramrobot/logging"
"github.com/pkg/errors"
"gopkg.in/telebot.v3"
)

Expand Down Expand Up @@ -42,7 +43,7 @@ func (m *MediaSender) sendSingleMedia(media *domain.Media) error {
File: telebot.FromURL(media.Url),
Caption: caption,
}); err != nil {
return errors.Wrap(err, "couldn't send the single video")
return fmt.Errorf("couldn't send the single video, %w", err)
}

logging.Debugf("Sent single video with short code [%v]", media.Shortcode)
Expand All @@ -51,7 +52,7 @@ func (m *MediaSender) sendSingleMedia(media *domain.Media) error {
File: telebot.FromURL(media.Url),
Caption: caption,
}); err != nil {
return errors.Wrap(err, "couldn't send the single photo")
return fmt.Errorf("couldn't send the single photo, %w", err)
}

logging.Debugf("Sent single photo with short code [%v]", media.Shortcode)
Expand All @@ -63,7 +64,7 @@ func (m *MediaSender) sendSingleMedia(media *domain.Media) error {
func (m *MediaSender) sendNestedMedia(media *domain.Media) error {
_, err := m.bot.SendAlbum(m.msg.Chat, m.generateAlbumFromMedia(media))
if err != nil {
return errors.Wrap(err, "couldn't send the nested media")
return fmt.Errorf("couldn't send the nested media, %w", err)
}
return m.SendCaption(media)
}
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.22
require (
github.com/EDDYCJY/fake-useragent v0.2.0
github.com/gocolly/colly/v2 v2.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.2
Expand All @@ -30,7 +29,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.14.0 // indirect
github.com/prometheus/procfs v0.15.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
github.com/temoto/robotstxt v1.1.2 // indirect
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -373,8 +372,8 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/procfs v0.14.0 h1:Lw4VdGGoKEZilJsayHf0B+9YgLGREba2C6xr+Fdfq6s=
github.com/prometheus/procfs v0.14.0/go.mod h1:XL+Iwz8k8ZabyZfMFHPiilCniixqQarAy5Mu67pHlNQ=
github.com/prometheus/procfs v0.15.0 h1:A82kmvXJq2jTu5YUhSGNlYoxh85zLnKgPz4bMZgI5Ek=
github.com/prometheus/procfs v0.15.0/go.mod h1:Y0RJ/Y5g5wJpkTisOtqwDSo4HwhGmLB4VQSw2sQJLHk=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
Expand Down

0 comments on commit b5c3e26

Please sign in to comment.