Skip to content

Commit

Permalink
get rid of confusing colorizeImpl with errFn
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth authored Dec 31, 2024
1 parent 3754626 commit b170016
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions internal/svg/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,25 @@ import (

// Colorize creates a new SVG from a given one by replacing all fill colors by the given color.
func Colorize(src []byte, clr color.Color) []byte {
return colorizeImpl(src, clr, fyne.LogError)
content, err := colorizeImpl(src, clr)

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / mobile_tests (1.19.x)

undefined: colorizeImpl

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.19.x, macos-latest)

undefined: colorizeImpl

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.23.x, macos-latest)

declared and not used: content

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.23.x, macos-latest)

undefined: colorizeImpl

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / mobile_tests (1.23.x)

declared and not used: content

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / mobile_tests (1.23.x)

undefined: colorizeImpl

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

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

declared and not used: content

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

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

undefined: colorizeImpl

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / static_analysis

declared and not used: content

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / static_analysis

undefined: colorizeImpl

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.19.x, ubuntu-latest)

undefined: colorizeImpl

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / windows_tests (1.20.x)

undefined: colorizeImpl

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / windows_tests (1.22.x)

content declared and not used

Check failure on line 25 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / windows_tests (1.22.x)

undefined: colorizeImpl
if err != nil {
fyne.LogError("", err)
}
}

Check failure on line 29 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / mobile_tests (1.19.x)

missing return

Check failure on line 29 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.19.x, macos-latest)

missing return

Check failure on line 29 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.23.x, macos-latest)

missing return

Check failure on line 29 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / mobile_tests (1.23.x)

missing return

Check failure on line 29 in internal/svg/svg.go

View workflow job for this annotation

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

missing return

Check failure on line 29 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / static_analysis

missing return

Check failure on line 29 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.19.x, ubuntu-latest)

missing return

Check failure on line 29 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / windows_tests (1.20.x)

missing return

Check failure on line 29 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / windows_tests (1.22.x)

missing return

// ColorizeError is the same as Colorize, except returning instead of logging any error.
func ColorizeError(src []byte, clr color.Color) ([]byte, error) {
var err error
content := colorizeImpl(src, clr, func(s string, e error) {
err = fmt.Errorf("%s %s", s, e.Error())
})
return content, err
}

func colorizeImpl(src []byte, clr color.Color, errFn func(string, error)) []byte {
rdr := bytes.NewReader(src)
s, err := svgFromXML(rdr)
if err != nil {
errFn("could not load SVG, falling back to static content:", err)
return src
return src, fmt.Errorf("could not load SVG, falling back to static content: %v", err)
}
if err := s.replaceFillColor(clr); err != nil {
errFn("could not replace fill color, falling back to static content:", err)
return src
return src, fmt.Errorf("could not replace fill color, falling back to static content: %v", err)
}
colorized, err := xml.Marshal(s)
if err != nil {
errFn("could not marshal svg, falling back to static content:", err)
return src
return src, fmt.Errorf("could not marshal svg, falling back to static content: %v", err)
}
return colorized

Check failure on line 45 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / mobile_tests (1.19.x)

not enough return values

Check failure on line 45 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.19.x, macos-latest)

not enough return values

Check failure on line 45 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.23.x, macos-latest)

not enough return values

Check failure on line 45 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / mobile_tests (1.23.x)

not enough return values

Check failure on line 45 in internal/svg/svg.go

View workflow job for this annotation

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

not enough return values

Check failure on line 45 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / static_analysis

not enough return values

Check failure on line 45 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.19.x, ubuntu-latest)

not enough return values

Check failure on line 45 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / windows_tests (1.20.x)

not enough return values

Check failure on line 45 in internal/svg/svg.go

View workflow job for this annotation

GitHub Actions / windows_tests (1.22.x)

not enough return values
}
Expand Down

0 comments on commit b170016

Please sign in to comment.