Skip to content

Commit 80661bb

Browse files
committed
Improve error handling in build process and fix spelling in success messages
1 parent c1036c6 commit 80661bb

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

pkg/leeway/build.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,13 @@ func Build(pkg *Package, opts ...BuildOption) (err error) {
533533

534534
buildErr := pkg.build(ctx)
535535

536+
// Check for build errors immediately and return if there are any
537+
if buildErr != nil {
538+
// We deliberately swallow the target package build error as that will have already been reported using the reporter.
539+
return xerrors.Errorf("build failed")
540+
}
541+
542+
// Only proceed with cache upload if build succeeded
536543
pkgsToUpload := ctx.GetNewPackagesForCache()
537544
// Convert []*Package to []cache.Package
538545
pkgsToUploadCache := make([]cache.Package, len(pkgsToUpload))
@@ -541,11 +548,6 @@ func Build(pkg *Package, opts ...BuildOption) (err error) {
541548
}
542549

543550
cacheErr := ctx.RemoteCache.Upload(context.Background(), ctx.LocalCache, pkgsToUploadCache)
544-
545-
if buildErr != nil {
546-
// We deliberately swallow the target pacakge build error as that will have already been reported using the reporter.
547-
return xerrors.Errorf("build failed")
548-
}
549551
if cacheErr != nil {
550552
return cacheErr
551553
}

pkg/leeway/reporter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (r *ConsoleReporter) BuildFinished(pkg *Package, err error) {
178178
return
179179
}
180180

181-
color.Println("\n<green>build succeded</>")
181+
color.Println("\n<green>build succeeded</>")
182182
}
183183

184184
// PackageBuildStarted is called when a package build actually gets underway.
@@ -219,7 +219,7 @@ func (r *ConsoleReporter) PackageBuildFinished(pkg *Package, rep *PackageBuildRe
219219
if rep.TestCoverageAvailable {
220220
coverage = color.Sprintf("<fg=yellow>test coverage: %d%%</> <gray>(%d of %d functions have tests)</>\n", rep.TestCoveragePercentage, rep.FunctionsWithTest, rep.FunctionsWithTest+rep.FunctionsWithoutTest)
221221
}
222-
msg := color.Sprintf("%s<green>package build succeded</> <gray>(%.2fs)</>\n", coverage, dur.Seconds())
222+
msg := color.Sprintf("%s<green>package build succeeded</> <gray>(%.2fs)</>\n", coverage, dur.Seconds())
223223
if rep.Error != nil {
224224
msg = color.Sprintf("<red>package build failed while %sing</>\n<white>Reason:</> %s\n", rep.LastPhase(), rep.Error)
225225
}
@@ -438,7 +438,7 @@ func (r *HTMLReporter) Report() {
438438
{{- range $pkg, $report := .Packages }}
439439
<h2 id="{{ $report.ID }}">{{ $report.StatusIcon }} {{ $pkg }}</h2>
440440
{{ if $report.HasError -}}
441-
<details open>
441+
<details open>
442442
<summary>Error message</summary>
443443
<pre><code>{{ $report.Error }}</code></pre>
444444
</details>

0 commit comments

Comments
 (0)