-
Notifications
You must be signed in to change notification settings - Fork 23
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
Conversation
- remove fmt to log package for printing issue
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
## Set Mongo DB | ||
1. The configuration of your mongo db should be in : mongodb://localhost:27017 | ||
|
There was a problem hiding this comment.
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 :)
"log" | ||
"math/rand" | ||
"os" | ||
"strconv" | ||
"time" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") |
There was a problem hiding this comment.
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 👍
|
||
func sendErrorToChan(err error, ID int64, errorTxt string) { | ||
log.Print(err) | ||
bot.Send(tbot.NewMessage(ID, errorTxt)) | ||
} |
There was a problem hiding this comment.
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.
log.Println(err) | ||
bot.Send(tbot.NewMessage(ID, "Error appears, please try again later")) | ||
return |
There was a problem hiding this comment.
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
Fixes #43