diff options
Diffstat (limited to 'internal/rosa/state.go')
| -rw-r--r-- | internal/rosa/state.go | 15 |
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 } |
