mirror of
https://salsa.debian.org/mdosch/feed-to-muc.git
synced 2024-11-22 14:08:39 +01:00
Added some error messages.
This commit is contained in:
parent
efac56edd6
commit
2f94e857d4
2 changed files with 31 additions and 31 deletions
|
@ -56,14 +56,14 @@ func main() {
|
|||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(configPath, 0700)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't create config path: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
} else { // Get the current user.
|
||||
curUser, err := user.Current()
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't get current user: ", err)
|
||||
return
|
||||
}
|
||||
// Get home directory.
|
||||
|
@ -79,7 +79,7 @@ func main() {
|
|||
if _, err := os.Stat(configPath + "config.json"); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(configPath, 0700)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't create config path: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ func main() {
|
|||
|
||||
// Check that config file is existing.
|
||||
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't find config file: ", err)
|
||||
}
|
||||
|
||||
// Read configuration file into variable config.
|
||||
|
@ -98,13 +98,13 @@ func main() {
|
|||
decoder := json.NewDecoder(file)
|
||||
config := configuration{}
|
||||
if err := decoder.Decode(&config); err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't decode config: ", err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(configPath, 0700)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't create config path: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,13 +122,13 @@ func main() {
|
|||
// Connect to server.
|
||||
client, err = options.NewClient()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Can't connect to xmpp server: ", err)
|
||||
}
|
||||
|
||||
// Join the MUC
|
||||
_, err := client.JoinMUCNoHistory(config.Muc, config.MucNick)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Can't join MUC: ", err)
|
||||
}
|
||||
|
||||
// Starting goroutine to ping the server every 30 seconds.
|
||||
|
@ -152,7 +152,7 @@ func main() {
|
|||
output, err := getArticles(config.Feeds[i], config.MaxArticles, config.NoExcerpt)
|
||||
if err != nil {
|
||||
// Exit if an error occurs checking the feeds.
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Can't check feeds for new articles: ", err)
|
||||
}
|
||||
|
||||
if output != "" {
|
||||
|
@ -161,7 +161,7 @@ func main() {
|
|||
if err != nil {
|
||||
// ToDo: Save message for resend.
|
||||
// Exit if message can not be sent.
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Can't send message to MUC: ", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ func pingMUC(client *xmpp.Client, botJid string, muc string, mucNick string) {
|
|||
id, err = client.RawInformation(botJid, muc+"/"+mucNick, sid.Id(),
|
||||
"get", "<ping xmlns='urn:xmpp:ping'/>")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Can't send MUC self ping: ", err)
|
||||
}
|
||||
|
||||
pingSent = time.Now()
|
||||
|
@ -208,7 +208,7 @@ func pingServer(client *xmpp.Client, server string, botJid string) {
|
|||
// Send ping to server to check if connection still exists.
|
||||
err := client.PingC2S(botJid, strings.Split(server, ":")[0])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Client2Server ping failed:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
|
|||
for { // Receive stanzas. ToDo: Receive stanzas continiously without 30s delay.
|
||||
stanza, err := client.Recv()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Failed receiving Stanzas:", err)
|
||||
}
|
||||
|
||||
// Check stanzas, maybe we want to reply.
|
||||
|
@ -254,7 +254,7 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
|
|||
"\"feeds\": List feeds I'm following.\n" +
|
||||
"\"source\": Show source code URL."})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Failed sending message to MUC:", err)
|
||||
}
|
||||
// Reply with repo address for `source`.
|
||||
case "source":
|
||||
|
@ -263,7 +263,7 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
|
|||
": My source can be found at " +
|
||||
"https://salsa.debian.org/mdosch-guest/feed-to-muc"})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Failed sending message to MUC:", err)
|
||||
}
|
||||
// Reply with the list of monitored feeds for `feeds`.
|
||||
case "feeds":
|
||||
|
@ -277,7 +277,7 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
|
|||
Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] +
|
||||
": Feeds I'm following:\n" + feedList})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Failed sending message to MUC:", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -301,13 +301,13 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
|
|||
"<identity category='client' type='bot' name='feedbot'/>"+
|
||||
"<feature var='http://jabber.org/protocol/disco#info'/></query>")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Failed to reply to disco#info:", err)
|
||||
}
|
||||
} else if strings.Contains(string(v.Query), "<ping xmlns='urn:xmpp:ping'/>") == true {
|
||||
// Reply to pings.
|
||||
_, err := client.RawInformation(client.JID(), v.From, v.ID, "result", "")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Failed to reply to ping:", err)
|
||||
}
|
||||
} else {
|
||||
// Send error replies for all other IQs.
|
||||
|
@ -315,7 +315,7 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str
|
|||
"<error type='cancel'><service-unavailable "+
|
||||
"xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error>")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("Error: Failed to send error IQ:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,14 +38,14 @@ func getArticles(feedURL string, max int, noExcerpt bool) (string, error) {
|
|||
if _, err := os.Stat(cachePath); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(cachePath, 0700)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't create cache path:", err)
|
||||
}
|
||||
}
|
||||
|
||||
} else { // Get the current user.
|
||||
curUser, err := user.Current()
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't get current user:", err)
|
||||
return "", err
|
||||
}
|
||||
// Get home directory.
|
||||
|
@ -61,7 +61,7 @@ func getArticles(feedURL string, max int, noExcerpt bool) (string, error) {
|
|||
if _, err := os.Stat(cachePath); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(cachePath, 0700)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't create cache path:", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ func getArticles(feedURL string, max int, noExcerpt bool) (string, error) {
|
|||
if _, err := os.Stat(cachePath); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(cachePath, 0700)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't create hash identifier for cache file:", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ func getArticles(feedURL string, max int, noExcerpt bool) (string, error) {
|
|||
if _, err := os.Stat(cacheFile); os.IsNotExist(err) {
|
||||
file, err = os.Create(cacheFile)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't create cache file:", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
|
@ -94,26 +94,26 @@ func getArticles(feedURL string, max int, noExcerpt bool) (string, error) {
|
|||
lastUpdateJSON, _ := json.MarshalIndent(lastUpdate, "", " ")
|
||||
_, err = file.Write(lastUpdateJSON)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't write last update time stamp to cache file:", err)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
file, err = os.OpenFile(cacheFile, os.O_RDWR, 0600)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't open cache file:", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
decoder := json.NewDecoder(file)
|
||||
lastUpdate := feedCache{}
|
||||
if err := decoder.Decode(&lastUpdate); err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't decode laste updates time stamp:", err)
|
||||
}
|
||||
|
||||
last, err = time.Parse(time.RFC3339, string(lastUpdate.LastChange))
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't parse last updates time stamp:", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,19 +179,19 @@ func getArticles(feedURL string, max int, noExcerpt bool) (string, error) {
|
|||
// ToDo: Replace timestamp without deleting.
|
||||
err = os.Remove(cacheFile)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't delete cache file:", err)
|
||||
}
|
||||
|
||||
file, err = os.Create(cacheFile)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't create cache file:", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
lastUpdateJSON, _ := json.MarshalIndent(lastUpdate, "", " ")
|
||||
_, err = file.Write(lastUpdateJSON)
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
log.Fatal("Error: Can't write last update time stamp to cache file:", err)
|
||||
}
|
||||
|
||||
// Remove redirects and tracking parameters from URL.
|
||||
|
|
Loading…
Reference in a new issue