aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--internal/rosa/go.go2
-rw-r--r--internal/rosa/rosa.go34
2 files changed, 31 insertions, 5 deletions
diff --git a/internal/rosa/go.go b/internal/rosa/go.go
index 866ee094..b0cf5c81 100644
--- a/internal/rosa/go.go
+++ b/internal/rosa/go.go
@@ -108,7 +108,7 @@ mkdir -p /var/tmp/
finalEnv = append(finalEnv, "CGO_ENABLED=0")
default:
- panic("unsupported target " + arch)
+ panic(TargetError(arch))
}
go119 := t.newGo(
diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go
index bb9dc317..22dbcd6d 100644
--- a/internal/rosa/rosa.go
+++ b/internal/rosa/rosa.go
@@ -1,6 +1,7 @@
package rosa
import (
+ "errors"
"os"
"slices"
"strconv"
@@ -59,6 +60,13 @@ var (
AbsSystem = fhs.AbsRoot.Append(prefixR)
)
+// TargetError is an unsupported target architecture name.
+type TargetError string
+
+func (e TargetError) Error() string {
+ return "unsupported target " + string(e)
+}
+
// linuxArch returns the architecture name used by linux corresponding to arch.
func linuxArch(arch string) string {
switch arch {
@@ -71,7 +79,7 @@ func linuxArch(arch string) string {
return arch
default:
- panic("unsupported target " + arch)
+ panic(TargetError(arch))
}
}
@@ -429,6 +437,24 @@ func (e BootstrapError) Error() string {
" must not be built by bootstrap stages"
}
+// A StageError describes an out-of-bounds stage value.
+type StageError Stage
+
+func (e StageError) Error() string {
+ return "invalid stage " + strconv.Itoa(int(e))
+}
+
+var (
+ // ErrBadName is returned by [Toolchain.New] attempting to create a package
+ // with an empty name or version string.
+ ErrBadName = errors.New("name must be non-empty")
+
+ // ErrChdir is returned by [Toolchain.New] if neither the package attributes
+ // nor the resolved helper request a directory, and the early script segment
+ // is not populated.
+ ErrChdir = errors.New("cannot remain in root")
+)
+
// New constructs a [pkg.Artifact] via a build system helper.
func (t Toolchain) New(
name, version string,
@@ -450,7 +476,7 @@ func (t Toolchain) New(
}
if name == "" || version == "" {
- panic("name must be non-empty")
+ panic(ErrBadName)
}
rn := name
if version != Unversioned {
@@ -533,7 +559,7 @@ func (t Toolchain) New(
}, Prefix+"/bin", "/bin")
default:
- panic("unsupported toolchain " + strconv.Itoa(int(t.stage)))
+ panic(StageError(t.stage))
}
wantsChmod, wantsWrite := helper.wantsChmod(), helper.wantsWrite()
@@ -616,7 +642,7 @@ cd '/usr/src/` + name + `/'
}
scriptEarly += "\ncd " + dir + "\n"
} else if !attr.EnterSource && attr.ScriptEarly == "" && dir != "" {
- panic("cannot remain in root")
+ panic(ErrChdir)
}
paths := attr.Paths