Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling #43 : migration from fatal to println #62

Closed
wants to merge 1 commit into from

Conversation

OgmaJ
Copy link

@OgmaJ OgmaJ commented Nov 10, 2020

Fixes #43

  • send error msg in case of error
  • remove fmt to log package for printing issue
  • update readme

 - remove fmt to log package for printing issue
Copy link
Member

@daemon1024 daemon1024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @OgmaJ 🎆 . I have requested some changes, please look into it.

@@ -1,5 +1,6 @@
logs
.exe
.idea
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Comment on lines +27 to +29
## Set Mongo DB
1. The configuration of your mongo db should be in : mongodb://localhost:27017

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. Proper setup instructions are already listed in https://github.com/osdc/bots/blob/master/CONTRIBUTING.md. We will update the README as part of #48 so it's not needed in this PR :)

Comment on lines +12 to +16
"log"
"math/rand"
"os"
"strconv"
"time"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert this? The existing order seemed to be better :)

@@ -47,7 +45,7 @@ func tweet() {

demux := twitter.NewSwitchDemux()
demux.Tweet = func(tweet *twitter.Tweet) {
fmt.Println(tweet.IDStr)
log.Println(tweet.IDStr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log prints out to stderr but this is not needed in stderr so the use of fmt is fine.

Suggested change
log.Println(tweet.IDStr)
fmt.Println(tweet.IDStr)

@@ -70,7 +68,7 @@ func xkcd(ID int64) {
for _, link := range links {
imglink := link.Attrs()["src"]
fullurl := "https:" + imglink
fmt.Println(fullurl)
log.Println(fullurl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Println(fullurl)
fmt.Println(fullurl)

@@ -192,7 +190,7 @@ func main() {
log.Fatal(err)
}

fmt.Println("Connected to MongoDB!")
log.Println("Connected to MongoDB!")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Println("Connected to MongoDB!")
fmt.Println("Connected to MongoDB!")

@@ -167,7 +165,7 @@ func main() {
var err error
bot, err = tbot.NewBotAPI(os.Getenv("TELEGRAM_TOKEN"))
if err != nil {
fmt.Println("error in auth")
log.Println("error in auth")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's justified here since we are logging the error 👍

Comment on lines +200 to +204

func sendErrorToChan(err error, ID int64, errorTxt string) {
log.Print(err)
bot.Send(tbot.NewMessage(ID, errorTxt))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare this in main.go then it should be accessible across all the files. So you can call the function in other functions not part of meetups too.

Comment on lines +42 to +44
log.Println(err)
bot.Send(tbot.NewMessage(ID, "Error appears, please try again later"))
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to the comment on sendErrorToChan in meetups.go

@OgmaJ OgmaJ closed this Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error handling
2 participants