From 1bc882bdb4c134238e8192afec93af337512f831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Men=C3=A9ndez?= Date: Thu, 14 Nov 2024 12:51:36 +0100 Subject: [PATCH] handling missing errors --- helpers_test.go | 7 ++- .../go-data-generator/generator_test.go | 6 +-- vt.go | 50 +++++++++++++------ 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/helpers_test.go b/helpers_test.go index ad8f6e9..c66cbac 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -3,7 +3,6 @@ package arbo import ( "bytes" "io" - "io/ioutil" "os" "testing" "time" @@ -41,13 +40,13 @@ func checkRoots(c *qt.C, tree1, tree2 *Tree) { func storeTree(c *qt.C, tree *Tree, path string) { dump, err := tree.Dump(nil) c.Assert(err, qt.IsNil) - err = ioutil.WriteFile(path+"-"+time.Now().String()+".debug", dump, 0600) + err = os.WriteFile(path+"-"+time.Now().String()+".debug", dump, 0600) c.Assert(err, qt.IsNil) } // nolint:unused func readTree(c *qt.C, tree *Tree, path string) { - b, err := ioutil.ReadFile(path) //nolint:gosec + b, err := os.ReadFile(path) //nolint:gosec c.Assert(err, qt.IsNil) err = tree.ImportDump(b) c.Assert(err, qt.IsNil) @@ -102,7 +101,7 @@ func TestReadTreeDBG(t *testing.T) { // tree1 is generated by a loop of .Add path := "err-dump/tree1-2021-06-03 16:45:54.104449306 +0200 CEST m=+0.073874545.debug" - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) c.Assert(err, qt.IsNil) err = importDumpLoopAdd(tree1, b) c.Assert(err, qt.IsNil) diff --git a/testvectors/circom/go-data-generator/generator_test.go b/testvectors/circom/go-data-generator/generator_test.go index 8974add..80bd2d3 100644 --- a/testvectors/circom/go-data-generator/generator_test.go +++ b/testvectors/circom/go-data-generator/generator_test.go @@ -2,8 +2,8 @@ package main import ( "encoding/json" - "io/ioutil" "math/big" + "os" "testing" qt "github.com/frankban/quicktest" @@ -42,7 +42,7 @@ func TestGenerator(t *testing.T) { jCvp, err := json.Marshal(cvp) c.Assert(err, qt.IsNil) // store the data into a file that will be used at the circom test - err = ioutil.WriteFile("go-smt-verifier-inputs.json", jCvp, 0600) + err = os.WriteFile("go-smt-verifier-inputs.json", jCvp, 0600) c.Assert(err, qt.IsNil) // proof of non-existence @@ -52,6 +52,6 @@ func TestGenerator(t *testing.T) { jCvp, err = json.Marshal(cvp) c.Assert(err, qt.IsNil) // store the data into a file that will be used at the circom test - err = ioutil.WriteFile("go-smt-verifier-non-existence-inputs.json", jCvp, 0600) + err = os.WriteFile("go-smt-verifier-non-existence-inputs.json", jCvp, 0600) c.Assert(err, qt.IsNil) } diff --git a/vt.go b/vt.go index 9115a79..b24293d 100644 --- a/vt.go +++ b/vt.go @@ -627,13 +627,17 @@ func (n *node) computeHashes(currLvl, maxLvl int, p *params, pairs [][2][]byte) //nolint:all func (t *vt) graphviz(w io.Writer) error { - fmt.Fprintf(w, `digraph hierarchy { + if _, err := fmt.Fprintf(w, `digraph hierarchy { node [fontname=Monospace,fontsize=10,shape=box] -`) +`); err != nil { + return err + } if _, err := t.root.graphviz(w, t.params, 0); err != nil { return err } - fmt.Fprintf(w, "}\n") + if _, err := fmt.Fprintf(w, "}\n"); err != nil { + return err + } return nil } @@ -650,7 +654,9 @@ func (n *node) graphviz(w io.Writer, p *params, nEmpties int) (int, error) { if err != nil { return nEmpties, err } - fmt.Fprintf(w, "\"%p\" [style=filled,label=\"%v\"];\n", n, hex.EncodeToString(leafKey[:nChars])) + if _, err := fmt.Fprintf(w, "\"%p\" [style=filled,label=\"%v\"];\n", n, hex.EncodeToString(leafKey[:nChars])); err != nil { + return nEmpties, err + } k := n.k v := n.v @@ -661,14 +667,20 @@ func (n *node) graphviz(w io.Writer, p *params, nEmpties int) (int, error) { v = n.v[:nChars] } - fmt.Fprintf(w, "\"%p\" -> {\"k:%v\\nv:%v\"}\n", n, + if _, err := fmt.Fprintf(w, "\"%p\" -> {\"k:%v\\nv:%v\"}\n", n, hex.EncodeToString(k), - hex.EncodeToString(v)) - fmt.Fprintf(w, "\"k:%v\\nv:%v\" [style=dashed]\n", + hex.EncodeToString(v)); err != nil { + return nEmpties, err + } + if _, err := fmt.Fprintf(w, "\"k:%v\\nv:%v\" [style=dashed]\n", hex.EncodeToString(k), - hex.EncodeToString(v)) + hex.EncodeToString(v)); err != nil { + return nEmpties, err + } case vtMid: - fmt.Fprintf(w, "\"%p\" [label=\"\"];\n", n) + if _, err := fmt.Fprintf(w, "\"%p\" [label=\"\"];\n", n); err != nil { + return nEmpties, err + } lStr := fmt.Sprintf("%p", n.l) rStr := fmt.Sprintf("%p", n.r) @@ -685,8 +697,12 @@ func (n *node) graphviz(w io.Writer, p *params, nEmpties int) (int, error) { rStr) nEmpties++ } - fmt.Fprintf(w, "\"%p\" -> {\"%v\" \"%v\"}\n", n, lStr, rStr) - fmt.Fprint(w, eStr) + if _, err := fmt.Fprintf(w, "\"%p\" -> {\"%v\" \"%v\"}\n", n, lStr, rStr); err != nil { + return nEmpties, err + } + if _, err := fmt.Fprint(w, eStr); err != nil { + return nEmpties, err + } nEmpties, err := n.l.graphviz(w, p, nEmpties) if err != nil { return nEmpties, err @@ -707,15 +723,19 @@ func (n *node) graphviz(w io.Writer, p *params, nEmpties int) (int, error) { //nolint:all func (t *vt) printGraphviz() error { w := bytes.NewBufferString("") - fmt.Fprintf(w, - "--------\nGraphviz:\n") + if _, err := fmt.Fprintf(w, + "--------\nGraphviz:\n"); err != nil { + return err + } err := t.graphviz(w) if err != nil { fmt.Println(w) return err } - fmt.Fprintf(w, - "End of Graphviz --------\n") + if _, err := fmt.Fprintf(w, + "End of Graphviz --------\n"); err != nil { + return err + } fmt.Println(w) return nil }