Skip to content

Commit 1f5da2e

Browse files
committed
feat: added better error reporting
1 parent 741f3df commit 1f5da2e

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

go.mod

100644100755
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ go 1.22
44

55
require (
66
github.com/evanw/esbuild v0.23.0
7+
github.com/fatih/color v1.17.0
78
github.com/fsnotify/fsnotify v1.7.0
89
github.com/spf13/cobra v1.8.1
910
)
1011

1112
require (
1213
github.com/inconshreveable/mousetrap v1.1.0 // indirect
14+
github.com/mattn/go-colorable v0.1.13 // indirect
15+
github.com/mattn/go-isatty v0.0.20 // indirect
1316
github.com/spf13/pflag v1.0.5 // indirect
14-
golang.org/x/sys v0.4.0 // indirect
17+
golang.org/x/sys v0.18.0 // indirect
1518
)

go.sum

100644100755
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
22
github.com/evanw/esbuild v0.23.0 h1:PLUwTn2pzQfIBRrMKcD3M0g1ALOKIHMDefdFCk7avwM=
33
github.com/evanw/esbuild v0.23.0/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48=
4+
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
5+
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
46
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
57
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
68
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
79
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
10+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
11+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
12+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
13+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
14+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
815
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
916
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
1017
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
1118
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
1219
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
1320
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14-
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
15-
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
21+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
22+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
23+
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
24+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1625
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1726
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/esbuild/esbuild.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"path/filepath"
88
"squish/internal/config"
99
"squish/internal/utils"
10+
"strings"
11+
12+
"github.com/fatih/color"
1013
)
1114

1215
type BundlerConfig struct {
@@ -127,7 +130,12 @@ func (b *Bundler) bundleEntry(sourcePath *utils.SourcePathResult, entry config.E
127130
}
128131

129132
if len(result.Errors) > 0 {
130-
return fmt.Errorf("build failed for %s: %v", entry.OutputPath, result.Errors)
133+
printBuildErrors(result.Errors)
134+
return fmt.Errorf("build failed for %s", entry.OutputPath)
135+
}
136+
137+
if len(result.Warnings) > 0 {
138+
printBuildWarnings(result.Warnings)
131139
}
132140

133141
return nil
@@ -214,3 +222,27 @@ func createEsbuildPlugin(p Plugin) api.Plugin {
214222
},
215223
}
216224
}
225+
226+
func printBuildErrors(errors []api.Message) {
227+
for _, err := range errors {
228+
printBuildMessage("Error", err, color.FgRed)
229+
}
230+
}
231+
232+
func printBuildWarnings(warnings []api.Message) {
233+
for _, warning := range warnings {
234+
printBuildMessage("Warning", warning, color.FgYellow)
235+
}
236+
}
237+
238+
func printBuildMessage(msgType string, msg api.Message, colorAttr color.Attribute) {
239+
c := color.New(colorAttr).Add(color.Bold)
240+
c.Printf("%s: %s\n", msgType, msg.Text)
241+
if msg.Location != nil {
242+
fmt.Printf("File: %s:%d:%d\n", msg.Location.File, msg.Location.Line, msg.Location.Column)
243+
fmt.Println(msg.Location.LineText)
244+
underline := strings.Repeat(" ", msg.Location.Column) + strings.Repeat("^", msg.Location.Length)
245+
fmt.Println(underline)
246+
}
247+
fmt.Println()
248+
}

0 commit comments

Comments
 (0)