Skip to content

Commit

Permalink
Handled previously unhandled errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dynos01 committed Sep 25, 2023
1 parent 9cd57b3 commit 9948b9e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
25 changes: 19 additions & 6 deletions cmd/dist-receiver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func main() {
http.HandleFunc("/next", next)
http.HandleFunc("/connect", connect)
go func() {
http.ListenAndServe("0.0.0.0:4002", nil)
if err := http.ListenAndServe("0.0.0.0:4002", nil); err != nil {
panic(fmt.Errorf("failed to spawn command receiver: %s", err))
}
}()

ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -57,26 +59,37 @@ func main() {
panic(fmt.Errorf("failed to spawn ephemeral node: %s", err))
}

connectToPeers(ctx, node, []string{args[1]})
if err := connectToPeers(ctx, node, []string{args[1]}); err != nil {
fmt.Fprintln(os.Stderr, "Failed to connect to root peer: {}", err)
}

stageNow = 1

<-sig

connectToPeers(ctx, node, targets)
if err := connectToPeers(ctx, node, targets); err != nil {
fmt.Fprintln(os.Stderr, "Failed to connect to peers: {}", err)
}

cid := icorepath.New(args[2])

node.Dht().Provide(ctx, cid)
node.Pin().Add(ctx, cid)
if err := node.Dht().Provide(ctx, cid); err != nil {
fmt.Fprintln(os.Stderr, "Failed to seed the resource file: {}", err)
}

if err := node.Pin().Add(ctx, cid); err != nil {
fmt.Fprintln(os.Stderr, "Failed to pin the resource file: {}", err)
}

rootNode, err := node.Unixfs().Get(ctx, cid)

if err != nil {
panic(fmt.Errorf("could not get file with CID: %s", err))
}

os.RemoveAll(args[3])
if err := os.RemoveAll(args[3]); err != nil {
panic(fmt.Errorf("could not clean previous temporary file: %s", err))
}

err = files.WriteTo(rootNode, args[3])
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/imagedistributor/p2p_distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ func (p *p2pDistributor) DistributeRegistry(deployHosts []net.IP, dataDir string

logrus.Infof("Distributing %s", info.MountDir)

p.distributeImpl(deployHosts, info.MountDir, dataDir)
if err := p.distributeImpl(deployHosts, info.MountDir, dataDir); err != nil {
return fmt.Errorf("failed to distribute: %s", err)
}
}

return nil
Expand All @@ -78,7 +80,9 @@ func (p *p2pDistributor) Distribute(hosts []net.IP, dest string) error {
return err
}

p.distributeImpl(hosts, info.MountDir, dest)
if err := p.distributeImpl(hosts, info.MountDir, dest); err != nil {
return fmt.Errorf("failed to distribute: %s", err)
}
}

return nil
Expand Down

0 comments on commit 9948b9e

Please sign in to comment.