From 479a4562798047a7a7b0ade96b084c5d3a9581ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 5 May 2020 18:14:47 +0200 Subject: [PATCH 1/2] chain bisect: Improve errors --- cli/chain.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/cli/chain.go b/cli/chain.go index e2f609846..dcb3bcf5f 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -692,7 +692,7 @@ var chainBisectCmd = &cli.Command{ highest, err := api.ChainGetTipSetByHeight(ctx, abi.ChainEpoch(end), types.EmptyTSK) if err != nil { - return err + return xerrors.Errorf("getting end tipset: %w", err) } prev := highest.Height() @@ -726,15 +726,32 @@ var chainBisectCmd = &cli.Command{ cmd.Stdin = bytes.NewReader(b) var out bytes.Buffer + var serr bytes.Buffer + cmd.Stdout = &out + cmd.Stderr = &serr switch cmd.Run().(type) { case nil: // it's lower - end = mid - highest = midTs - fmt.Println("true") + if strings.TrimSpace(out.String()) == "true" { + end = mid + highest = midTs + fmt.Println("true") + } else { + start = mid + fmt.Printf("false ('%s' not 'true')\n", strings.TrimSpace(out.String())) + } case *exec.ExitError: + if len(serr.String()) > 0 { + fmt.Println("error") + + fmt.Printf("> Command: %s\n---->\n", strings.Join(cctx.Args().Slice()[3:], " ")) + fmt.Println(string(b)) + fmt.Println("<----") + return xerrors.Errorf("error running bisect check: %s", serr.String()) + } + start = mid fmt.Println("false") default: From 4cd861eb87190b1944800356ccaca77348e1f286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 5 May 2020 18:15:12 +0200 Subject: [PATCH 2/2] chain bisect: json-marshar the correct thing --- cli/chain.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/chain.go b/cli/chain.go index dcb3bcf5f..f39e06542 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -717,7 +717,7 @@ var chainBisectCmd = &cli.Command{ return err } - b, err := json.MarshalIndent(nd, "", "\t") + b, err := json.MarshalIndent(nd.Obj, "", "\t") if err != nil { return err } @@ -734,13 +734,13 @@ var chainBisectCmd = &cli.Command{ switch cmd.Run().(type) { case nil: // it's lower - if strings.TrimSpace(out.String()) == "true" { + if strings.TrimSpace(out.String()) != "false" { end = mid highest = midTs fmt.Println("true") } else { start = mid - fmt.Printf("false ('%s' not 'true')\n", strings.TrimSpace(out.String())) + fmt.Printf("false (cli)\n") } case *exec.ExitError: if len(serr.String()) > 0 {