mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +08:00
fix: correct Errorf/Fatalf argument handling
- Fix incorrect argument passing to log.Errorf and log.Fatalf functions - Remove debugging comments, temporary tests, and print statements - Address linter warnings related to error logging
This commit is contained in:
parent
024259e480
commit
7f5dfae904
@ -17,19 +17,18 @@ func NewErrorHandler(continueOnError bool) *FatalErrorHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *FatalErrorHandler) Handle(err error, format string, args ...interface{}) {
|
func (h *FatalErrorHandler) Handle(err error, format string, args ...interface{}) {
|
||||||
errorMesage := fmt.Sprintf(format, args...)
|
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if h.ContinueOnError {
|
if h.ContinueOnError {
|
||||||
log.Error(errorMesage)
|
log.Error(fmt.Sprintf(format, args...))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Fatal(errorMesage)
|
log.Fatal(fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.ContinueOnError {
|
if h.ContinueOnError {
|
||||||
log.Errorf(err, errorMesage)
|
log.Errorf(err, format, args...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Fatalf(err, errorMesage)
|
log.Fatalf(err, format, args...)
|
||||||
}
|
}
|
||||||
|
46
main.go
46
main.go
@ -47,7 +47,7 @@ var flags = []cli.Flag{
|
|||||||
altsrc.NewBoolFlag(&cli.BoolFlag{
|
altsrc.NewBoolFlag(&cli.BoolFlag{
|
||||||
Name: "continue-on-error",
|
Name: "continue-on-error",
|
||||||
Value: false,
|
Value: false,
|
||||||
Usage: "dont exit if an error occurs while processing a file, continue processing remaining files.",
|
Usage: "don't exit if an error occurs while processing a file, continue processing remaining files.",
|
||||||
EnvVars: []string{"MARK_CONTINUE_ON_ERROR"},
|
EnvVars: []string{"MARK_CONTINUE_ON_ERROR"},
|
||||||
}),
|
}),
|
||||||
altsrc.NewBoolFlag(&cli.BoolFlag{
|
altsrc.NewBoolFlag(&cli.BoolFlag{
|
||||||
@ -284,9 +284,6 @@ func RunMark(cCtx *cli.Context) error {
|
|||||||
|
|
||||||
fatalErrorHandler := NewErrorHandler(cCtx.Bool("continue-on-error"))
|
fatalErrorHandler := NewErrorHandler(cCtx.Bool("continue-on-error"))
|
||||||
|
|
||||||
fmt.Printf("Processing %d files\n", len(files))
|
|
||||||
fmt.Printf("continue-on-error: %t\n", cCtx.Bool("continue-on-error"))
|
|
||||||
|
|
||||||
// Loop through files matched by glob pattern
|
// Loop through files matched by glob pattern
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
log.Infof(
|
log.Infof(
|
||||||
@ -321,7 +318,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to read file %q", file)
|
fatalErrorHandler.Handle(err, "unable to read file %q", file)
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
markdown = bytes.ReplaceAll(markdown, []byte("\r\n"), []byte("\n"))
|
markdown = bytes.ReplaceAll(markdown, []byte("\r\n"), []byte("\n"))
|
||||||
@ -332,7 +328,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to extract metadata from file %q", file)
|
fatalErrorHandler.Handle(err, "unable to extract metadata from file %q", file)
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if pageID != "" && meta != nil {
|
if pageID != "" && meta != nil {
|
||||||
@ -347,35 +342,22 @@ func processFile(
|
|||||||
if pageID == "" && meta == nil {
|
if pageID == "" && meta == nil {
|
||||||
fatalErrorHandler.Handle(nil, "specified file doesn't contain metadata and URL is not specified via command line or doesn't contain pageId GET-parameter")
|
fatalErrorHandler.Handle(nil, "specified file doesn't contain metadata and URL is not specified via command line or doesn't contain pageId GET-parameter")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(
|
|
||||||
// `specified file doesn't contain metadata ` +
|
|
||||||
// `and URL is not specified via command line ` +
|
|
||||||
// `or doesn't contain pageId GET-parameter`,
|
|
||||||
// )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta.Space == "" {
|
if meta.Space == "" {
|
||||||
fatalErrorHandler.Handle(nil, "space is not set ('Space' header is not set and '--space' option is not set)")
|
fatalErrorHandler.Handle(nil, "space is not set ('Space' header is not set and '--space' option is not set)")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(
|
|
||||||
// "space is not set ('Space' header is not set and '--space' option is not set)",
|
|
||||||
// )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta.Title == "" {
|
if meta.Title == "" {
|
||||||
fatalErrorHandler.Handle(nil, "page title is not set ('Title' header is not set and '--title-from-h1' option and 'h1_title' config is not set or there is no H1 in the file)")
|
fatalErrorHandler.Handle(nil, "page title is not set ('Title' header is not set and '--title-from-h1' option and 'h1_title' config is not set or there is no H1 in the file)")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(
|
|
||||||
// `page title is not set ('Title' header is not set ` +
|
|
||||||
// `and '--title-from-h1' option and 'h1_title' config is not set or there is no H1 in the file)`,
|
|
||||||
// )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stdlib, err := stdlib.New(api)
|
stdlib, err := stdlib.New(api)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to retrieve standard library")
|
fatalErrorHandler.Handle(err, "unable to retrieve standard library")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
templates := stdlib.Templates
|
templates := stdlib.Templates
|
||||||
@ -392,7 +374,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to process includes")
|
fatalErrorHandler.Handle(err, "unable to process includes")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !recurse {
|
if !recurse {
|
||||||
@ -409,7 +390,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to extract macros")
|
fatalErrorHandler.Handle(err, "unable to extract macros")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macros = append(macros, stdlib.Macros...)
|
macros = append(macros, stdlib.Macros...)
|
||||||
@ -419,7 +399,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to apply macro")
|
fatalErrorHandler.Handle(err, "unable to apply macro")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,7 +406,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to resolve relative links")
|
fatalErrorHandler.Handle(err, "unable to resolve relative links")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatalf(err, "unable to resolve relative links")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
markdown = page.SubstituteLinks(markdown, links)
|
markdown = page.SubstituteLinks(markdown, links)
|
||||||
@ -437,7 +415,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to resolve page location")
|
fatalErrorHandler.Handle(err, "unable to resolve page location")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatalf(err, "unable to resolve page location")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,11 +434,6 @@ func processFile(
|
|||||||
if meta != nil {
|
if meta != nil {
|
||||||
parent, page, err := page.ResolvePage(cCtx.Bool("dry-run"), api, meta)
|
parent, page, err := page.ResolvePage(cCtx.Bool("dry-run"), api, meta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// log.Fatalf(
|
|
||||||
// karma.Describe("title", meta.Title).Reason(err),
|
|
||||||
// "unable to resolve %s",
|
|
||||||
// meta.Type,
|
|
||||||
// )
|
|
||||||
fatalErrorHandler.Handle(karma.Describe("title", meta.Title).Reason(err), "unable to resolve %s", meta.Type)
|
fatalErrorHandler.Handle(karma.Describe("title", meta.Title).Reason(err), "unable to resolve %s", meta.Type)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -477,12 +449,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "can't create %s %q", meta.Type, meta.Title)
|
fatalErrorHandler.Handle(err, "can't create %s %q", meta.Type, meta.Title)
|
||||||
return nil
|
return nil
|
||||||
// log.Fatalf(
|
|
||||||
// err,
|
|
||||||
// "can't create %s %q",
|
|
||||||
// meta.Type,
|
|
||||||
// meta.Title,
|
|
||||||
// )
|
|
||||||
}
|
}
|
||||||
// (issues/139): A delay between the create and update call
|
// (issues/139): A delay between the create and update call
|
||||||
// helps mitigate a 409 conflict that can occur when attempting
|
// helps mitigate a 409 conflict that can occur when attempting
|
||||||
@ -495,14 +461,12 @@ func processFile(
|
|||||||
if pageID == "" {
|
if pageID == "" {
|
||||||
fatalErrorHandler.Handle(nil, "URL should provide 'pageId' GET-parameter")
|
fatalErrorHandler.Handle(nil, "URL should provide 'pageId' GET-parameter")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatalf(nil, "URL should provide 'pageId' GET-parameter")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
page, err := api.GetPageByID(pageID)
|
page, err := api.GetPageByID(pageID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to retrieve page by id")
|
fatalErrorHandler.Handle(err, "unable to retrieve page by id")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatalf(err, "unable to retrieve page by id")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
target = page
|
target = page
|
||||||
@ -513,7 +477,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to locate attachments")
|
fatalErrorHandler.Handle(err, "unable to locate attachments")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatalf(err, "unable to locate attachments")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
attaches, err := attachment.ResolveAttachments(
|
attaches, err := attachment.ResolveAttachments(
|
||||||
@ -524,7 +487,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to create/update attachments")
|
fatalErrorHandler.Handle(err, "unable to create/update attachments")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatalf(err, "unable to create/update attachments")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
markdown = attachment.CompileAttachmentLinks(markdown, attaches)
|
markdown = attachment.CompileAttachmentLinks(markdown, attaches)
|
||||||
@ -546,7 +508,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to create/update attachments")
|
fatalErrorHandler.Handle(err, "unable to create/update attachments")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatalf(err, "unable to create/update attachments")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -568,7 +529,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to execute layout template")
|
fatalErrorHandler.Handle(err, "unable to execute layout template")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
html = buffer.String()
|
html = buffer.String()
|
||||||
@ -618,7 +578,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to update page")
|
fatalErrorHandler.Handle(err, "unable to update page")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,7 +597,6 @@ func processFile(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "unable to restrict page updates")
|
fatalErrorHandler.Handle(err, "unable to restrict page updates")
|
||||||
return nil
|
return nil
|
||||||
// log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -670,7 +628,6 @@ func updateLabels(api *confluence.API, target *confluence.PageInfo, meta *metada
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "error adding labels")
|
fatalErrorHandler.Handle(err, "error adding labels")
|
||||||
return false
|
return false
|
||||||
// log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,7 +636,6 @@ func updateLabels(api *confluence.API, target *confluence.PageInfo, meta *metada
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fatalErrorHandler.Handle(err, "error deleting labels")
|
fatalErrorHandler.Handle(err, "error deleting labels")
|
||||||
return false
|
return false
|
||||||
// log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
15
testdata/batch-tests/broken-test.md
vendored
15
testdata/batch-tests/broken-test.md
vendored
@ -1,15 +0,0 @@
|
|||||||
# a
|
|
||||||
|
|
||||||
## b
|
|
||||||
|
|
||||||
### c
|
|
||||||
|
|
||||||
#### d
|
|
||||||
|
|
||||||
##### e
|
|
||||||
|
|
||||||
# f
|
|
||||||
|
|
||||||
## g
|
|
||||||
|
|
||||||
# This/is some_Heading.yml
|
|
10
testdata/batch-tests/irfan-test.md
vendored
10
testdata/batch-tests/irfan-test.md
vendored
@ -1,10 +0,0 @@
|
|||||||
<!-- Space: MySpace -->
|
|
||||||
<!-- Parent: Parent -->
|
|
||||||
<!-- Title: whatnot -->
|
|
||||||
|
|
||||||
## Foo
|
|
||||||
|
|
||||||
> **TL;DR:** Thingy!
|
|
||||||
> More stuff
|
|
||||||
|
|
||||||
Foo
|
|
15
testdata/batch-tests/mark-test.md
vendored
15
testdata/batch-tests/mark-test.md
vendored
@ -1,15 +0,0 @@
|
|||||||
# a
|
|
||||||
|
|
||||||
## b
|
|
||||||
|
|
||||||
### c
|
|
||||||
|
|
||||||
#### d
|
|
||||||
|
|
||||||
##### e
|
|
||||||
|
|
||||||
# f
|
|
||||||
|
|
||||||
## g
|
|
||||||
|
|
||||||
# This/is some_Heading.yml
|
|
19
testdata/batch-tests/rich-test.md
vendored
19
testdata/batch-tests/rich-test.md
vendored
@ -1,19 +0,0 @@
|
|||||||
<!-- Space: TEST2 -->
|
|
||||||
<!-- Title: H2 -->
|
|
||||||
<!-- Title: whatnot -->
|
|
||||||
|
|
||||||
# a
|
|
||||||
|
|
||||||
## b
|
|
||||||
|
|
||||||
### c
|
|
||||||
|
|
||||||
#### d
|
|
||||||
|
|
||||||
##### e
|
|
||||||
|
|
||||||
# f
|
|
||||||
|
|
||||||
## g
|
|
||||||
|
|
||||||
# This/is some_Heading.yml
|
|
Loading…
x
Reference in New Issue
Block a user