From 91c3594dee2f1689501997d395af7019df8bebe2 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 12 Jan 2026 03:53:19 +0900 Subject: internal/pkg: append user-facing name in messages This makes verbose messages much more useful. Signed-off-by: Ophestra --- internal/pkg/pkg.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'internal/pkg/pkg.go') diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go index 60898b48..c1a3f97e 100644 --- a/internal/pkg/pkg.go +++ b/internal/pkg/pkg.go @@ -8,6 +8,7 @@ import ( "encoding/base64" "encoding/binary" "errors" + "fmt" "io" "io/fs" "os" @@ -278,6 +279,20 @@ func Ident(a Artifact) ID { return a.Kind().Ident(a.Params(), a.Dependencies()...) } +// reportNameIdent is like reportName but does not recompute [ID]. +func reportNameIdent(a Artifact, id ID) string { + r := Encode(id) + if s, ok := a.(fmt.Stringer); ok { + if name := s.String(); name != "" { + r += "-" + name + } + } + return r +} + +// reportName returns a string describing [Artifact] presented to the user. +func reportName(a Artifact) string { return reportNameIdent(a, Ident(a)) } + // Kind corresponds to the concrete type of [Artifact] and is used to create // identifier for an [Artifact] with dependencies. type Kind uint64 @@ -725,6 +740,9 @@ func (c *Cache) openFile(f File) (r io.ReadCloser, err error) { if !errors.Is(err, os.ErrNotExist) { return } + if c.msg.IsVerbose() { + c.msg.Verbosef("curing %s to memory...", reportName(f)) + } var data []byte if data, err = f.Cure(c.ctx); err != nil { return @@ -917,7 +935,7 @@ func (c *Cache) Cure(a Artifact) ( } if c.msg.IsVerbose() { - c.msg.Verbosef("curing %s...", Encode(id)) + c.msg.Verbosef("curing %s...", reportNameIdent(a, id)) } // cure File outside type switch to skip TContext initialisation -- cgit v1.3.1