Skip to content

Commit

Permalink
more handling missing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Nov 14, 2024
1 parent 1bc882b commit 168f957
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -1463,9 +1463,11 @@ func (t *Tree) Graphviz(w io.Writer, fromRoot []byte) error {
// generate a string Graphviz representation of the first NLevels of the tree
// and writes it to w
func (t *Tree) GraphvizFirstNLevels(w io.Writer, fromRoot []byte, untilLvl int) 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 fromRoot == nil {
var err error
fromRoot, err = t.RootWithTx(t.db)
Expand All @@ -1482,14 +1484,20 @@ node [fontname=Monospace,fontsize=10,shape=box]
switch v[0] {
case PrefixValueEmpty:
case PrefixValueLeaf:
fmt.Fprintf(w, "\"%v\" [style=filled];\n", hex.EncodeToString(k[:nChars]))
if _, err := fmt.Fprintf(w, "\"%v\" [style=filled];\n", hex.EncodeToString(k[:nChars])); err != nil {

Check failure on line 1487 in tree.go

View workflow job for this annotation

GitHub Actions / lint (1.23.x, ubuntu-latest)

the line is 104 characters long, which exceeds the maximum of 100 characters. (lll)
return false
}
// key & value from the leaf
kB, vB := ReadLeafValue(v)
fmt.Fprintf(w, "\"%v\" -> {\"k:%v\\nv:%v\"}\n",
if _, err := fmt.Fprintf(w, "\"%v\" -> {\"k:%v\\nv:%v\"}\n",
hex.EncodeToString(k[:nChars]), hex.EncodeToString(kB[:nChars]),
hex.EncodeToString(vB[:nChars]))
fmt.Fprintf(w, "\"k:%v\\nv:%v\" [style=dashed]\n",
hex.EncodeToString(kB[:nChars]), hex.EncodeToString(vB[:nChars]))
hex.EncodeToString(vB[:nChars])); err != nil {
return false
}
if _, err := fmt.Fprintf(w, "\"k:%v\\nv:%v\" [style=dashed]\n",
hex.EncodeToString(kB[:nChars]), hex.EncodeToString(vB[:nChars])); err != nil {
return false
}
case PrefixValueIntermediate:
l, r := ReadIntermediateChilds(v)
lStr := hex.EncodeToString(l[:nChars])
Expand All @@ -1507,14 +1515,20 @@ node [fontname=Monospace,fontsize=10,shape=box]
rStr)
nEmpties++
}
fmt.Fprintf(w, "\"%v\" -> {\"%v\" \"%v\"}\n", hex.EncodeToString(k[:nChars]),
lStr, rStr)
fmt.Fprint(w, eStr)
if _, err := fmt.Fprintf(w, "\"%v\" -> {\"%v\" \"%v\"}\n", hex.EncodeToString(k[:nChars]),
lStr, rStr); err != nil {
return false
}
if _, err := fmt.Fprint(w, eStr); err != nil {
return false
}
default:
}
return false
})
fmt.Fprintf(w, "}\n")
if _, err := fmt.Fprintf(w, "}\n"); err != nil {
return err
}
return err
}

Expand All @@ -1540,15 +1554,19 @@ func (t *Tree) PrintGraphvizFirstNLevels(fromRoot []byte, untilLvl int) error {
}
}
w := bytes.NewBufferString("")
fmt.Fprintf(w,
"--------\nGraphviz of the Tree with Root "+hex.EncodeToString(fromRoot)+":\n")
if _, err := fmt.Fprintf(w,
"--------\nGraphviz of the Tree with Root "+hex.EncodeToString(fromRoot)+":\n"); err != nil {

Check failure on line 1558 in tree.go

View workflow job for this annotation

GitHub Actions / lint (1.23.x, ubuntu-latest)

printf: non-constant format string in call to fmt.Fprintf (govet)
return err
}
err := t.GraphvizFirstNLevels(w, fromRoot, untilLvl)
if err != nil {
fmt.Println(w)
return err
}
fmt.Fprintf(w,
"End of Graphviz of the Tree with Root "+hex.EncodeToString(fromRoot)+"\n--------\n")
if _, err := fmt.Fprintf(w,
"End of Graphviz of the Tree with Root "+hex.EncodeToString(fromRoot)+"\n--------\n"); err != nil {

Check failure on line 1567 in tree.go

View workflow job for this annotation

GitHub Actions / lint (1.23.x, ubuntu-latest)

the line is 101 characters long, which exceeds the maximum of 100 characters. (lll)
return err
}

fmt.Println(w)
return nil
Expand Down

0 comments on commit 168f957

Please sign in to comment.