refactor: replace karma-go with standard error handling

This commit is contained in:
Manuel Rüger
2026-03-28 10:16:29 +01:00
parent e160121005
commit 0859bf4d08
12 changed files with 69 additions and 215 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"fmt"
"image" "image"
_ "image/gif" _ "image/gif"
_ "image/jpeg" _ "image/jpeg"
@@ -18,7 +19,6 @@ import (
"github.com/kovetskiy/mark/v16/confluence" "github.com/kovetskiy/mark/v16/confluence"
"github.com/kovetskiy/mark/v16/vfs" "github.com/kovetskiy/mark/v16/vfs"
"github.com/reconquest/karma-go"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
@@ -50,10 +50,7 @@ func ResolveAttachments(
for i := range attachments { for i := range attachments {
checksum, err := GetChecksum(bytes.NewReader(attachments[i].FileBytes)) checksum, err := GetChecksum(bytes.NewReader(attachments[i].FileBytes))
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("unable to get checksum for attachment %q: %w", attachments[i].Name, err)
err,
"unable to get checksum for attachment: %q", attachments[i].Name,
)
} }
attachments[i].Checksum = checksum attachments[i].Checksum = checksum
@@ -61,7 +58,7 @@ func ResolveAttachments(
remotes, err := api.GetAttachments(page.ID) remotes, err := api.GetAttachments(page.ID)
if err != nil { if err != nil {
return nil, karma.Format(err, "unable to get attachments for page %s", page.ID) return nil, fmt.Errorf("unable to get attachments for page %s: %w", page.ID, err)
} }
existing := []Attachment{} existing := []Attachment{}
@@ -110,11 +107,7 @@ func ResolveAttachments(
bytes.NewReader(attachment.FileBytes), bytes.NewReader(attachment.FileBytes),
) )
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("unable to create attachment %q: %w", attachment.Name, err)
err,
"unable to create attachment %q",
attachment.Name,
)
} }
attachment.ID = info.ID attachment.ID = info.ID
@@ -137,11 +130,7 @@ func ResolveAttachments(
bytes.NewReader(attachment.FileBytes), bytes.NewReader(attachment.FileBytes),
) )
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("unable to update attachment %q: %w", attachment.Name, err)
err,
"unable to update attachment %q",
attachment.Name,
)
} }
attachment.Link = path.Join( attachment.Link = path.Join(
@@ -173,10 +162,7 @@ func ResolveLocalAttachments(opener vfs.Opener, base string, replacements []stri
for i := range attachments { for i := range attachments {
checksum, err := GetChecksum(bytes.NewReader(attachments[i].FileBytes)) checksum, err := GetChecksum(bytes.NewReader(attachments[i].FileBytes))
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("unable to get checksum for attachment %q: %w", attachments[i].Name, err)
err,
"unable to get checksum for attachment: %q", attachments[i].Name,
)
} }
attachments[i].Checksum = checksum attachments[i].Checksum = checksum
@@ -204,7 +190,7 @@ func prepareAttachment(opener vfs.Opener, base, name string) (Attachment, error)
attachmentPath := filepath.Join(base, name) attachmentPath := filepath.Join(base, name)
file, err := opener.Open(attachmentPath) file, err := opener.Open(attachmentPath)
if err != nil { if err != nil {
return Attachment{}, karma.Format(err, "unable to open file: %q", attachmentPath) return Attachment{}, fmt.Errorf("unable to open file %q: %w", attachmentPath, err)
} }
defer func() { defer func() {
_ = file.Close() _ = file.Close()
@@ -212,7 +198,7 @@ func prepareAttachment(opener vfs.Opener, base, name string) (Attachment, error)
fileBytes, err := io.ReadAll(file) fileBytes, err := io.ReadAll(file)
if err != nil { if err != nil {
return Attachment{}, karma.Format(err, "unable to read file: %q", attachmentPath) return Attachment{}, fmt.Errorf("unable to read file %q: %w", attachmentPath, err)
} }
attachment := Attachment{ attachment := Attachment{

View File

@@ -13,7 +13,6 @@ import (
"unicode/utf8" "unicode/utf8"
"github.com/kovetskiy/gopencils" "github.com/kovetskiy/gopencils"
"github.com/reconquest/karma-go"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
@@ -147,11 +146,7 @@ func NewAPI(baseURL string, username string, password string, insecureSkipVerify
func (api *API) FindRootPage(space string) (*PageInfo, error) { func (api *API) FindRootPage(space string) (*PageInfo, error) {
page, err := api.FindPage(space, ``, "page") page, err := api.FindPage(space, ``, "page")
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("can't obtain first page from space %q: %w", space, err)
err,
"can't obtain first page from space %q",
space,
)
} }
if page == nil { if page == nil {
@@ -353,11 +348,7 @@ func (api *API) UpdateAttachment(
err = json.Unmarshal(result, &extendedResponse) err = json.Unmarshal(result, &extendedResponse)
if err != nil { if err != nil {
return info, karma.Format( return info, fmt.Errorf("unable to unmarshal JSON response as full response format (JSON=%s): %w", string(result), err)
err,
"unable to unmarshal JSON response as full response format: %s",
string(result),
)
} }
if len(extendedResponse.Results) > 0 { if len(extendedResponse.Results) > 0 {
@@ -377,11 +368,7 @@ func (api *API) UpdateAttachment(
var shortResponse AttachmentInfo var shortResponse AttachmentInfo
err = json.Unmarshal(result, &shortResponse) err = json.Unmarshal(result, &shortResponse)
if err != nil { if err != nil {
return info, karma.Format( return info, fmt.Errorf("unable to unmarshal JSON response as short response format (JSON=%s): %w", string(result), err)
err,
"unable to unmarshal JSON response as short response format: %s",
string(result),
)
} }
return shortResponse, nil return shortResponse, nil
@@ -395,42 +382,27 @@ func getAttachmentPayload(name, comment string, reader io.Reader) (*form, error)
content, err := writer.CreateFormFile("file", name) content, err := writer.CreateFormFile("file", name)
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("unable to create form file: %w", err)
err,
"unable to create form file",
)
} }
_, err = io.Copy(content, reader) _, err = io.Copy(content, reader)
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("unable to copy i/o between form-file and file: %w", err)
err,
"unable to copy i/o between form-file and file",
)
} }
commentWriter, err := writer.CreateFormField("comment") commentWriter, err := writer.CreateFormField("comment")
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("unable to create form field for comment: %w", err)
err,
"unable to create form field for comment",
)
} }
_, err = commentWriter.Write([]byte(comment)) _, err = commentWriter.Write([]byte(comment))
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("unable to write comment in form-field: %w", err)
err,
"unable to write comment in form-field",
)
} }
err = writer.Close() err = writer.Close()
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("unable to close form-writer: %w", err)
err,
"unable to close form-writer",
)
} }
return &form{ return &form{
@@ -753,11 +725,7 @@ func (api *API) GetUserByName(name string) (*User, error) {
if len(response.Results) == 0 { if len(response.Results) == 0 {
return nil, karma. return nil, fmt.Errorf("user with name %q is not found", name)
Describe("name", name).
Reason(
"user with given name is not found",
)
} }
return &response.Results[0].User, nil return &response.Results[0].User, nil

1
go.mod
View File

@@ -8,7 +8,6 @@ require (
github.com/chromedp/chromedp v0.15.1 github.com/chromedp/chromedp v0.15.1
github.com/dreampuf/mermaid.go v0.0.40 github.com/dreampuf/mermaid.go v0.0.40
github.com/kovetskiy/gopencils v0.0.0-20250404051442-0b776066936a github.com/kovetskiy/gopencils v0.0.0-20250404051442-0b776066936a
github.com/reconquest/karma-go v1.5.0
github.com/rs/zerolog v1.35.0 github.com/rs/zerolog v1.35.0
github.com/stefanfritsch/goldmark-admonitions v1.1.1 github.com/stefanfritsch/goldmark-admonitions v1.1.1
github.com/stretchr/testify v1.11.1 github.com/stretchr/testify v1.11.1

2
go.sum
View File

@@ -73,8 +73,6 @@ github.com/orisano/pixelmatch v0.0.0-20230914042517-fa304d1dc785/go.mod h1:nZgzb
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/reconquest/karma-go v1.5.0 h1:Chn4LtauwnvKfz13ZbmGNrRLKO1NciExHQSOBOsQqt4=
github.com/reconquest/karma-go v1.5.0/go.mod h1:52XRXXa2ec/VNrlCirwasdJfNmjI1O87q098gmqILh0=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=

View File

@@ -11,7 +11,6 @@ import (
"go.yaml.in/yaml/v3" "go.yaml.in/yaml/v3"
"github.com/reconquest/karma-go"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
@@ -35,8 +34,7 @@ func LoadTemplate(
templates *template.Template, templates *template.Template,
) (*template.Template, error) { ) (*template.Template, error) {
var ( var (
name = strings.TrimSuffix(path, filepath.Ext(path)) name = strings.TrimSuffix(path, filepath.Ext(path))
facts = karma.Describe("name", name)
) )
if template := templates.Lookup(name); template != nil { if template := templates.Lookup(name); template != nil {
@@ -51,11 +49,7 @@ func LoadTemplate(
body, err = os.ReadFile(filepath.Join(includePath, path)) body, err = os.ReadFile(filepath.Join(includePath, path))
} }
if err != nil { if err != nil {
err = facts.Format( return nil, fmt.Errorf("unable to read template file %q: %w", path, err)
err,
"unable to read template file",
)
return nil, err
} }
} }
@@ -68,12 +62,7 @@ func LoadTemplate(
templates, err = templates.New(name).Delims(left, right).Parse(string(body)) templates, err = templates.New(name).Delims(left, right).Parse(string(body))
if err != nil { if err != nil {
err = facts.Format( return nil, fmt.Errorf("unable to parse template %q: %w", name, err)
err,
"unable to parse template",
)
return nil, err
} }
return templates, nil return templates, nil
@@ -85,23 +74,15 @@ func ProcessIncludes(
contents []byte, contents []byte,
templates *template.Template, templates *template.Template,
) (*template.Template, []byte, bool, error) { ) (*template.Template, []byte, bool, error) {
vardump := func( formatVardump := func(
facts *karma.Context,
data map[string]interface{}, data map[string]interface{},
) *karma.Context { ) string {
var parts []string
for key, value := range data { for key, value := range data {
key = "var " + key parts = append(parts, fmt.Sprintf("%s=%v", key, value))
facts = facts.Describe(
key,
strings.ReplaceAll(
fmt.Sprint(value),
"\n",
"\n"+strings.Repeat(" ", len(key)+2),
),
)
} }
return facts return strings.Join(parts, ", ")
} }
var ( var (
@@ -125,8 +106,6 @@ func ProcessIncludes(
right = string(groups[4]) right = string(groups[4])
config = groups[5] config = groups[5]
data = map[string]interface{}{} data = map[string]interface{}{}
facts = karma.Describe("path", path)
) )
if delimsNone == "none" { if delimsNone == "none" {
@@ -136,21 +115,16 @@ func ProcessIncludes(
err = yaml.Unmarshal(config, &data) err = yaml.Unmarshal(config, &data)
if err != nil { if err != nil {
err = facts. err = fmt.Errorf("unable to unmarshal template data config (path=%q, config=%q): %w", path, string(config), err)
Describe("config", string(config)).
Format(
err,
"unable to unmarshal template data config",
)
return spec return spec
} }
log.Trace().Interface("vardump", vardump(facts, data)).Msgf("including template %q", path) log.Trace().Interface("vardump", data).Msgf("including template %q", path)
templates, err = LoadTemplate(base, includePath, path, left, right, templates) templates, err = LoadTemplate(base, includePath, path, left, right, templates)
if err != nil { if err != nil {
err = facts.Format(err, "unable to load template") err = fmt.Errorf("unable to load template %q: %w", path, err)
return spec return spec
} }
@@ -158,10 +132,7 @@ func ProcessIncludes(
err = templates.Execute(&buffer, data) err = templates.Execute(&buffer, data)
if err != nil { if err != nil {
err = vardump(facts, data).Format( err = fmt.Errorf("unable to execute template %q (vars: %s): %w", path, formatVardump(data), err)
err,
"unable to execute template",
)
return spec return spec
} }

View File

@@ -41,10 +41,7 @@ func (macro *Macro) Apply(
err = yaml.Unmarshal([]byte(macro.Config), &config) err = yaml.Unmarshal([]byte(macro.Config), &config)
if err != nil { if err != nil {
err = karma.Format( err = fmt.Errorf("unable to unmarshal macros config template: %w", err)
err,
"unable to unmarshal macros config template",
)
return match return match
} }
@@ -55,10 +52,7 @@ func (macro *Macro) Apply(
macro.Regexp.FindSubmatch(match), macro.Regexp.FindSubmatch(match),
)) ))
if err != nil { if err != nil {
err = karma.Format( err = fmt.Errorf("unable to execute macros template: %w", err)
err,
"unable to execute macros template",
)
return match return match
} }
@@ -136,10 +130,7 @@ func ExtractMacros(
err = yaml.Unmarshal([]byte(config), &cfg) err = yaml.Unmarshal([]byte(config), &cfg)
if err != nil { if err != nil {
err = karma.Format( err = fmt.Errorf("unable to unmarshal macros config template: %w", err)
err,
"unable to unmarshal macros config template",
)
return nil return nil
} }
@@ -156,33 +147,22 @@ func ExtractMacros(
macro.Template, err = templates.New(template).Parse(body) macro.Template, err = templates.New(template).Parse(body)
if err != nil { if err != nil {
err = karma.Format( err = fmt.Errorf("unable to parse template: %w", err)
err,
"unable to parse template",
)
return nil return nil
} }
} else { } else {
macro.Template, err = includes.LoadTemplate(base, includePath, template, "{{", "}}", templates) macro.Template, err = includes.LoadTemplate(base, includePath, template, "{{", "}}", templates)
if err != nil { if err != nil {
err = karma.Format(err, "unable to load template") err = fmt.Errorf("unable to load template: %w", err)
return nil return nil
} }
} }
facts := karma.
Describe("template", template).
Describe("expr", expr)
macro.Regexp, err = regexp.Compile(expr) macro.Regexp, err = regexp.Compile(expr)
if err != nil { if err != nil {
err = facts. err = fmt.Errorf("unable to compile macros regexp (expr=%q, template=%q): %w", expr, template, err)
Format(
err,
"unable to compile macros regexp",
)
return nil return nil
} }
@@ -190,7 +170,11 @@ func ExtractMacros(
macro.Config = config macro.Config = config
log.Trace(). log.Trace().
Interface("vardump", facts.Describe("config", macro.Config)). Interface("vardump", map[string]interface{}{
"expr": expr,
"template": template,
"config": macro.Config,
}).
Msgf("loaded macro %q", expr) Msgf("loaded macro %q", expr)
macros = append(macros, macro) macros = append(macros, macro)

View File

@@ -24,7 +24,6 @@ import (
"github.com/kovetskiy/mark/v16/stdlib" "github.com/kovetskiy/mark/v16/stdlib"
"github.com/kovetskiy/mark/v16/types" "github.com/kovetskiy/mark/v16/types"
"github.com/kovetskiy/mark/v16/vfs" "github.com/kovetskiy/mark/v16/vfs"
"github.com/reconquest/karma-go"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
@@ -286,7 +285,7 @@ func ProcessFile(file string, api *confluence.API, config Config) (*confluence.P
if meta != nil { if meta != nil {
parent, pg, err := page.ResolvePage(false, api, meta) parent, pg, err := page.ResolvePage(false, api, meta)
if err != nil { if err != nil {
return nil, karma.Describe("title", meta.Title).Reason(err) return nil, fmt.Errorf("error resolving page %q: %w", meta.Title, err)
} }
if pg == nil { if pg == nil {

View File

@@ -5,7 +5,6 @@ import (
"strings" "strings"
"github.com/kovetskiy/mark/v16/confluence" "github.com/kovetskiy/mark/v16/confluence"
"github.com/reconquest/karma-go"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
@@ -22,11 +21,7 @@ func EnsureAncestry(
for i, title := range ancestry { for i, title := range ancestry {
page, err := api.FindPage(space, title, "page") page, err := api.FindPage(space, title, "page")
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("error during finding parent page with title %q: %w", title, err)
err,
`error during finding parent page with title %q`,
title,
)
} }
if page == nil { if page == nil {
@@ -44,11 +39,7 @@ func EnsureAncestry(
} else { } else {
page, err := api.FindRootPage(space) page, err := api.FindRootPage(space)
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("can't find root page for space %q: %w", space, err)
err,
"can't find root page for space %q",
space,
)
} }
parent = page parent = page
@@ -68,11 +59,7 @@ func EnsureAncestry(
for _, title := range rest { for _, title := range rest {
page, err := api.CreatePage(space, "page", parent, title, ``) page, err := api.CreatePage(space, "page", parent, title, ``)
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("error during creating parent page with title %q: %w", title, err)
err,
`error during creating parent page with title %q`,
title,
)
} }
parent = page parent = page
@@ -108,11 +95,7 @@ func ValidateAncestry(
if len(page.Ancestors) < 1 { if len(page.Ancestors) < 1 {
homepage, err := api.FindHomePage(space) homepage, err := api.FindHomePage(space)
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("can't obtain home page from space %q: %w", space, err)
err,
"can't obtain home page from space %q",
space,
)
} }
if page.ID == homepage.ID { if page.ID == homepage.ID {
@@ -148,10 +131,10 @@ func ValidateAncestry(
} }
if !valid { if !valid {
return nil, karma.Describe("title", page.Title). return nil, fmt.Errorf(
Describe("actual", strings.Join(actual, " > ")). "the page has fewer parents than expected: title=%q, actual=[%s], expected=[%s]",
Describe("expected", strings.Join(ancestry, " > ")). page.Title, strings.Join(actual, " > "), strings.Join(ancestry, " > "),
Format(nil, "the page has fewer parents than expected") )
} }
} }
@@ -173,12 +156,10 @@ func ValidateAncestry(
list = append(list, ancestor.Title) list = append(list, ancestor.Title)
} }
return nil, karma.Describe("expected parent", parent). return nil, fmt.Errorf(
Describe("list", strings.Join(list, "; ")). "unexpected ancestry tree, did not find expected parent page %q in the tree: actual=[%s]",
Format( parent, strings.Join(list, "; "),
nil, )
"unexpected ancestry tree, did not find expected parent page in the tree",
)
} }
} }

View File

@@ -14,7 +14,6 @@ import (
"github.com/kovetskiy/mark/v16/confluence" "github.com/kovetskiy/mark/v16/confluence"
"github.com/kovetskiy/mark/v16/metadata" "github.com/kovetskiy/mark/v16/metadata"
"github.com/reconquest/karma-go"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
@@ -60,7 +59,7 @@ func ResolveRelativeLinks(
) )
resolved, err := resolveLink(api, base, match, spaceForLinks, titleFromH1, titleFromFilename, parents, titleAppendGeneratedHash) resolved, err := resolveLink(api, base, match, spaceForLinks, titleFromH1, titleFromFilename, parents, titleAppendGeneratedHash)
if err != nil { if err != nil {
return nil, karma.Format(err, "resolve link: %q", match.full) return nil, fmt.Errorf("resolve link %q: %w", match.full, err)
} }
if resolved == "" { if resolved == "" {
@@ -103,7 +102,7 @@ func resolveLink(
linkContents, err := os.ReadFile(filepath) linkContents, err := os.ReadFile(filepath)
if err != nil { if err != nil {
return "", karma.Format(err, "read file: %s", filepath) return "", fmt.Errorf("read file %s: %w", filepath, err)
} }
contentType := http.DetectContentType(linkContents) contentType := http.DetectContentType(linkContents)
@@ -146,13 +145,7 @@ func resolveLink(
result, err = getConfluenceLink(api, linkMeta.Space, linkMeta.Title) result, err = getConfluenceLink(api, linkMeta.Space, linkMeta.Title)
if err != nil { if err != nil {
return "", karma.Format( return "", fmt.Errorf("find confluence page (file=%s, space=%s, title=%s): %w", filepath, linkMeta.Space, linkMeta.Title, err)
err,
"find confluence page: %s / %s / %s",
filepath,
linkMeta.Space,
linkMeta.Title,
)
} }
if result == "" { if result == "" {
@@ -217,14 +210,14 @@ func getConfluenceLink(
// Try to find as a page first // Try to find as a page first
page, err := api.FindPage(space, title, "page") page, err := api.FindPage(space, title, "page")
if err != nil { if err != nil {
return "", karma.Format(err, "api: find page") return "", fmt.Errorf("api: find page %q in space %q: %w", title, space, err)
} }
// If not found as a page, try to find as a blog post // If not found as a page, try to find as a blog post
if page == nil { if page == nil {
page, err = api.FindPage(space, title, "blogpost") page, err = api.FindPage(space, title, "blogpost")
if err != nil { if err != nil {
return "", karma.Format(err, "api: find blogpost") return "", fmt.Errorf("api: find blogpost %q in space %q: %w", title, space, err)
} }
} }
@@ -242,7 +235,7 @@ func getConfluenceLink(
tiny, err := GenerateTinyLink(baseURL, page.ID) tiny, err := GenerateTinyLink(baseURL, page.ID)
if err != nil { if err != nil {
return "", karma.Format(err, "generate tiny link for page %s", page.ID) return "", fmt.Errorf("generate tiny link for page %s: %w", page.ID, err)
} }
return tiny, nil return tiny, nil

View File

@@ -1,11 +1,11 @@
package page package page
import ( import (
"fmt"
"strings" "strings"
"github.com/kovetskiy/mark/v16/confluence" "github.com/kovetskiy/mark/v16/confluence"
"github.com/kovetskiy/mark/v16/metadata" "github.com/kovetskiy/mark/v16/metadata"
"github.com/reconquest/karma-go"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
@@ -15,15 +15,11 @@ func ResolvePage(
meta *metadata.Meta, meta *metadata.Meta,
) (*confluence.PageInfo, *confluence.PageInfo, error) { ) (*confluence.PageInfo, *confluence.PageInfo, error) {
if meta == nil { if meta == nil {
return nil, nil, karma.Format(nil, "metadata is empty") return nil, nil, fmt.Errorf("metadata is empty")
} }
page, err := api.FindPage(meta.Space, meta.Title, meta.Type) page, err := api.FindPage(meta.Space, meta.Title, meta.Type)
if err != nil { if err != nil {
return nil, nil, karma.Format( return nil, nil, fmt.Errorf("error while finding page %q: %w", meta.Title, err)
err,
"error while finding page %q",
meta.Title,
)
} }
if meta.Type == "blogpost" { if meta.Type == "blogpost" {
@@ -39,11 +35,7 @@ func ResolvePage(
// check to see if home page is in Parents // check to see if home page is in Parents
homepage, err := api.FindHomePage(meta.Space) homepage, err := api.FindHomePage(meta.Space)
if err != nil { if err != nil {
return nil, nil, karma.Format( return nil, nil, fmt.Errorf("can't obtain home page from space %q: %w", meta.Space, err)
err,
"can't obtain home page from space %q",
meta.Space,
)
} }
skipHomeAncestry := false skipHomeAncestry := false
@@ -93,11 +85,7 @@ func ResolvePage(
meta.Parents, meta.Parents,
) )
if err != nil { if err != nil {
return nil, nil, karma.Format( return nil, nil, fmt.Errorf("can't create ancestry tree %q: %w", strings.Join(meta.Parents, ` > `), err)
err,
"can't create ancestry tree: %s",
strings.Join(meta.Parents, ` > `),
)
} }
titles := []string{} titles := []string{}

View File

@@ -1,14 +1,13 @@
package stdlib package stdlib
import ( import (
"fmt"
"html" "html"
"strings" "strings"
"text/template" "text/template"
"github.com/kovetskiy/mark/v16/confluence" "github.com/kovetskiy/mark/v16/confluence"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/reconquest/karma-go"
) )
type Lib struct { type Lib struct {
@@ -445,12 +444,7 @@ func templates(api *confluence.API) (*template.Template, error) {
} { } {
templates, err = templates.New(name).Parse(body) templates, err = templates.New(name).Parse(body)
if err != nil { if err != nil {
return nil, karma. return nil, fmt.Errorf("unable to parse template %q (body=%s): %w", name, body, err)
Describe("template", body).
Format(
err,
"unable to parse template",
)
} }
} }

View File

@@ -2,12 +2,11 @@ package util
import ( import (
"errors" "errors"
"fmt"
"io" "io"
"net/url" "net/url"
"os" "os"
"strings" "strings"
"github.com/reconquest/karma-go"
) )
type Credentials struct { type Credentials struct {
@@ -40,10 +39,7 @@ func GetCredentials(
if password == "-" { if password == "-" {
stdin, err := io.ReadAll(os.Stdin) stdin, err := io.ReadAll(os.Stdin)
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("unable to read password from stdin: %w", err)
err,
"unable to read password from stdin",
)
} }
password = strings.TrimSpace(string(stdin)) password = strings.TrimSpace(string(stdin))
@@ -55,10 +51,7 @@ func GetCredentials(
url, err := url.Parse(targetURL) url, err := url.Parse(targetURL)
if err != nil { if err != nil {
return nil, karma.Format( return nil, fmt.Errorf("unable to parse %q as url: %w", targetURL, err)
err,
"unable to parse %q as url", targetURL,
)
} }
if url.Host == "" && baseURL == "" { if url.Host == "" && baseURL == "" {