Skip to content

Commit

Permalink
Merge pull request #1648 from mrpalide/fix/remove-panic-from-skywirec…
Browse files Browse the repository at this point in the history
…li-log

improve `skywire-cli log` command
  • Loading branch information
jdknives authored Jul 17, 2023
2 parents 059faff + 172e8e5 commit 01b5f1b
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions cmd/skywire-cli/commands/log/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,31 @@ var logCmd = &cobra.Command{
log.Fatal("use of mutually exclusive flags --log and --survey")
}

ctx, cancel := cmdutil.SignalContext(context.Background(), log)
defer cancel()
go func() {
<-ctx.Done()
cancel()
os.Exit(1)
}()

// Preparing directories
if _, err := os.ReadDir("log_collecting"); err != nil {
if err := os.Mkdir("log_collecting", 0750); err != nil {
log.Panic("Unable to log_collecting directory")
log.Error("Unable to log_collecting directory")
return
}
}

if err := os.Chdir("log_collecting"); err != nil {
log.Panic("Unable to change directory to log_collecting")
log.Error("Unable to change directory to log_collecting")
return
}

// Create dmsgget instance
dg := dmsgget.New(flag.CommandLine)
flag.Parse()

ctx, cancel := cmdutil.SignalContext(context.Background(), log)
defer cancel()
go func() {
<-ctx.Done()
cancel()
os.Exit(1)
}()
// Set the uptime tracker to fetch data from
endpoint := skyenv.UptimeTrackerAddr + "/uptimes?v=v2"
if env == "test" {
Expand All @@ -105,7 +108,8 @@ var logCmd = &cobra.Command{
//Fetch the uptime data over http
uptimes, err := getUptimes(endpoint, log)
if err != nil {
log.WithError(err).Panic("Unable to get data from uptime tracker.")
log.WithError(err).Error("Unable to get data from uptime tracker.")
return
}
//randomize the order of the survey collection - workaround for hanging
rand.Shuffle(len(uptimes), func(i, j int) {
Expand All @@ -119,7 +123,8 @@ var logCmd = &cobra.Command{

dmsgC, closeDmsg, err := dg.StartDmsg(ctx, log, pk, sk)
if err != nil {
log.WithError(err).Panic(err)
log.Error(err)
return
}
defer closeDmsg()

Expand Down Expand Up @@ -156,7 +161,8 @@ var logCmd = &cobra.Command{
deleteOnError := false
if _, err := os.ReadDir(key); err != nil {
if err := os.Mkdir(key, 0750); err != nil {
log.Panicf("Unable to create directory for visor %s", key)
log.Errorf("Unable to create directory for visor %s", key)
return
}
deleteOnError = true
}
Expand Down

0 comments on commit 01b5f1b

Please sign in to comment.