forked from rosa/hakurei
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>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user