fix(help): use go-log E() pattern for error handling in catalog
Some checks failed
Build and Deploy / deploy (push) Failing after 6s
Some checks failed
Build and Deploy / deploy (push) Failing after 6s
Replace fmt.Errorf calls with log.E() structured errors in LoadContentDir and Get, providing operation context for the error chain. Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
791d64833d
commit
9744714be3
3 changed files with 9 additions and 5 deletions
1
go.mod
1
go.mod
|
|
@ -12,6 +12,7 @@ require (
|
|||
require (
|
||||
forge.lthn.ai/core/go-i18n v0.1.4 // indirect
|
||||
forge.lthn.ai/core/go-inference v0.1.4 // indirect
|
||||
forge.lthn.ai/core/go-log v0.0.4 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
golang.org/x/text v0.35.0 // indirect
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -4,6 +4,8 @@ forge.lthn.ai/core/go-i18n v0.1.4 h1:zOHUUJDgRo88/3tj++kN+VELg/buyZ4T2OSdG3HBbLQ
|
|||
forge.lthn.ai/core/go-i18n v0.1.4/go.mod h1:aDyAfz7MMgWYgLkZCptfFmZ7jJg3ocwjEJ1WkJSvv4U=
|
||||
forge.lthn.ai/core/go-inference v0.1.4 h1:fuAgWbqsEDajHniqAKyvHYbRcBrkGEiGSqR2pfTMRY0=
|
||||
forge.lthn.ai/core/go-inference v0.1.4/go.mod h1:jfWz+IJX55wAH98+ic6FEqqGB6/P31CHlg7VY7pxREw=
|
||||
forge.lthn.ai/core/go-log v0.0.4 h1:KTuCEPgFmuM8KJfnyQ8vPOU1Jg654W74h8IJvfQMfv0=
|
||||
forge.lthn.ai/core/go-log v0.0.4/go.mod h1:r14MXKOD3LF/sI8XUJQhRk/SZHBE7jAFVuCfgkXoZPw=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package help
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"iter"
|
||||
"maps"
|
||||
|
|
@ -9,6 +8,8 @@ import (
|
|||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
log "forge.lthn.ai/core/go-log"
|
||||
)
|
||||
|
||||
// Catalog manages help topics.
|
||||
|
|
@ -114,19 +115,19 @@ func LoadContentDir(dir string) (*Catalog, error) {
|
|||
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading %s: %w", path, err)
|
||||
return log.E("catalog.LoadContentDir", "reading "+path, err)
|
||||
}
|
||||
|
||||
topic, err := ParseTopic(path, content)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing %s: %w", path, err)
|
||||
return log.E("catalog.LoadContentDir", "parsing "+path, err)
|
||||
}
|
||||
|
||||
c.Add(topic)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("walking directory %s: %w", dir, err)
|
||||
return nil, log.E("catalog.LoadContentDir", "walking directory "+dir, err)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
|
|
@ -136,7 +137,7 @@ func LoadContentDir(dir string) (*Catalog, error) {
|
|||
func (c *Catalog) Get(id string) (*Topic, error) {
|
||||
t, ok := c.topics[id]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("topic not found: %s", id)
|
||||
return nil, log.E("catalog.Get", "topic not found: "+id, nil)
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue