Skip to content

Commit 7a59dac

Browse files
author
Hugo Müller-Downing
committed
Replace panics with returned errors
1 parent 80e1397 commit 7a59dac

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Diff for: lib/providers/cloudflare/cloudflare.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cloudflare
22

33
import (
4+
"errors"
45
"github.com/hugomd/cloudflare-ddns/lib/providers"
56
"log"
67
"os"
@@ -52,7 +53,7 @@ func NewProvider() (providers.Provider, error) {
5253
func (api *Cloudflare) UpdateRecord(ip string) error {
5354
zones, err := api.client.ListZones()
5455
if err != nil {
55-
panic(err)
56+
return err
5657
}
5758

5859
var zone Zone
@@ -64,12 +65,12 @@ func (api *Cloudflare) UpdateRecord(ip string) error {
6465
}
6566

6667
if zone == (Zone{}) {
67-
panic("Zone not found")
68+
return errors.New("Zone not found")
6869
}
6970

7071
records, err := api.client.ListDNSRecords(zone)
7172
if err != nil {
72-
panic(err)
73+
return err
7374
}
7475

7576
var record Record
@@ -80,14 +81,14 @@ func (api *Cloudflare) UpdateRecord(ip string) error {
8081
}
8182

8283
if record == (Record{}) {
83-
panic("Host not found")
84+
return errors.New("Host not found")
8485
}
8586

8687
if ip != record.Content {
8788
record.Content = ip
8889
err = api.client.UpdateDNSRecord(record, zone)
8990
if err != nil {
90-
panic(err)
91+
return err
9192
}
9293
log.Printf("IP changed, updated to %s", ip)
9394
} else {

0 commit comments

Comments
 (0)