Skip to content

Commit

Permalink
resolves #33 pkg/replace errors by fmt (stdlib)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Dec 8, 2022
1 parent b6961f1 commit f0a0ac7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/yuzutech/kroki-cli
go 1.18

require (
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.6.0
github.com/spf13/viper v1.13.0
github.com/yuzutech/kroki-go v0.8.1
Expand All @@ -17,6 +16,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand Down
13 changes: 4 additions & 9 deletions pkg/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"
"strings"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/yuzutech/kroki-go"
Expand Down Expand Up @@ -164,9 +163,7 @@ func ImageFormatFromValue(imageFormatRaw string) (kroki.ImageFormat, error) {
if f, ok := getImageFormatExtensions()["."+value]; ok {
return f, nil
}
return "", errors.Errorf(
"invalid image format %s.",
value)
return "", fmt.Errorf("invalid image format: %s", value)
}

func ImageFormatFromFile(filePath string) (kroki.ImageFormat, error) {
Expand All @@ -175,9 +172,7 @@ func ImageFormatFromFile(filePath string) (kroki.ImageFormat, error) {
if f, ok := getImageFormatExtensions()[value]; ok {
return f, nil
}
return "", errors.Errorf(
"invalid image format %s.",
value)
return "", fmt.Errorf("invalid image format: %s", value)
}

func ResolveGraphFormat(graphFormatRaw string, filePath string) (kroki.DiagramType, error) {
Expand All @@ -203,8 +198,8 @@ func GraphFormatFromFile(filePath string) (kroki.DiagramType, error) {
if d, ok := getDiagramTypeExtensions()[fileExtension]; ok {
return d, nil
}
return "", errors.Errorf(
"unable to infer the graph format from the file extension %s, please specify the diagram type using --type flag.",
return "", fmt.Errorf(
"unable to infer the graph format from the file extension %s, please specify the diagram type using --type flag",
value)
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"path"
"strings"

"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -59,11 +58,11 @@ func DecodeInput(input string) (string, error) {
}
result, err := base64.URLEncoding.DecodeString(input)
if err != nil {
return "", errors.Wrap(err, "fail to decode the input")
return "", fmt.Errorf("fail to decode the input: %w", err)
}
reader, err := zlib.NewReader(bytes.NewReader(result))
if err != nil {
return "", errors.Wrap(err, "fail to create the reader")
return "", fmt.Errorf("fail to create the reader: %w", err)
}
out := new(strings.Builder)
_, _ = io.Copy(out, reader)
Expand All @@ -78,7 +77,7 @@ func getUrl(input string) (*url.URL, error) {

u, err := url.Parse(input)
if err != nil || u.Scheme == "" || u.Host == "" {
return u, errors.New("invalid URL")
return u, fmt.Errorf("invalid URL")
}

return u, nil
Expand Down
6 changes: 2 additions & 4 deletions pkg/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"bufio"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/yuzutech/kroki-go"
)
Expand Down Expand Up @@ -35,9 +33,9 @@ func EncodeFromReader(reader io.Reader) {
}

func EncodeFromFile(filePath string) {
content, err := ioutil.ReadFile(filePath)
content, err := os.ReadFile(filePath)
if err != nil {
exit(errors.Wrapf(err, "fail to read file '%s'", filePath))
exit(fmt.Errorf("fail to read file %s: %w", filePath, err))
}
input := string(content)
result, err := kroki.CreatePayload(input)
Expand Down

0 comments on commit f0a0ac7

Please sign in to comment.