aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/state.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-05-18 00:07:39 +0900
committerOphestra <cat@gensokyo.uk>2026-05-18 00:07:39 +0900
commit3e236333a77233cfcd96b6fc93be91e14ab7c680 (patch)
tree97b4bc6703d6763a0c24455a33ce18d637966c1c /internal/rosa/state.go
parentf24ae21af111e0ce34f62a37ddb4a9fc18166ae6 (diff)
internal/rosa: panic error for invalid handle
This enables recovery and better error handling for errors originating from external azalea files. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/rosa/state.go')
-rw-r--r--internal/rosa/state.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/internal/rosa/state.go b/internal/rosa/state.go
index 89ee1840..67cfdf97 100644
--- a/internal/rosa/state.go
+++ b/internal/rosa/state.go
@@ -19,6 +19,9 @@ import (
// ArtifactH is a handle of the unique name of a prepared [pkg.Artifact].
type ArtifactH unique.Handle[string]
+// H is a convenient function for acquiring an [ArtifactH] by name.
+func H(name string) ArtifactH { return ArtifactH(unique.Make(name)) }
+
// String returns the name of p.
func (handle ArtifactH) String() string {
return unique.Handle[string](handle).Value()
@@ -39,6 +42,14 @@ func (handle *ArtifactH) UnmarshalJSON(data []byte) error {
return nil
}
+// A HandleError is panicked when attempting to acquire an [Artifact] via an
+// invalid [ArtifactH] with the Must suite of methods.
+type HandleError ArtifactH
+
+func (e HandleError) Error() string {
+ return "artifact " + strconv.Quote(ArtifactH(e).String()) + " not available"
+}
+
type (
// Stage denotes the infrastructure to compile a [pkg.Artifact] on.
Stage uint32
@@ -234,7 +245,7 @@ func (s *S) Get(handle ArtifactH) (meta *Artifact) {
func (s *S) MustGet(handle ArtifactH) (meta *Artifact) {
meta = s.Get(handle)
if meta == nil {
- panic("artifact " + strconv.Quote(handle.String()) + " not available")
+ panic(HandleError(handle))
}
return
}
@@ -270,7 +281,7 @@ func (t Toolchain) Load(handle ArtifactH) (pkg.Artifact, string) {
func (t Toolchain) MustLoad(handle ArtifactH) (pkg.Artifact, string) {
a, version := t.Load(handle)
if a == nil {
- panic("artifact " + strconv.Quote(handle.String()) + " not available")
+ panic(HandleError(handle))
}
return a, version
}