Skip to content

Commit 851b957

Browse files
committed
Reuse message across tag validation
1 parent ff03bd0 commit 851b957

3 files changed

Lines changed: 20 additions & 13 deletions

File tree

internal/api/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func (c *PlatformClient) GetLicense(ctx context.Context, licReq *LicenseRequest)
313313
if strings.Contains(detail, "licensing.license.format") {
314314
return nil, &LicenseError{
315315
Status: statusCode,
316-
Message: "unsupported image tag — check the tag in your config file",
316+
Message: version.UnsupportedTagMessage(),
317317
Detail: detail,
318318
}
319319
}

internal/config/containers.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
"regexp"
88
"strconv"
99
"strings"
10-
"time"
10+
11+
"github.com/localstack/lstk/internal/version"
1112
)
1213

1314
type EmulatorType string
@@ -120,22 +121,12 @@ var zeroPaddedMonthTagRe = regexp.MustCompile(`^(\d{4}\.)0([1-9].*)$`)
120121
// must not start with a dot or hyphen; max 128 characters.
121122
var validTagRe = regexp.MustCompile(`^[a-zA-Z0-9_][a-zA-Z0-9._-]*$`)
122123

123-
// prevMonthExample returns the previous calendar month as a tag example, e.g. "2026.4".
124-
func prevMonthExample() string {
125-
y, m, _ := time.Now().Date()
126-
m--
127-
if m == 0 {
128-
m, y = 12, y-1
129-
}
130-
return fmt.Sprintf("%d.%d", y, int(m))
131-
}
132-
133124
func validateTag(tag string) error {
134125
if tag == "" {
135126
return nil
136127
}
137128
if len(tag) > 128 || !validTagRe.MatchString(tag) || zeroPaddedMonthTagRe.MatchString(tag) {
138-
return fmt.Errorf("tag %q is not supported — try a tag like %q or \"latest\" in your config file", tag, prevMonthExample())
129+
return fmt.Errorf("tag %q is not supported — %s", tag, version.UnsupportedTagMessage())
139130
}
140131
return nil
141132
}

internal/version/version.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
package version
22

3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
38
// Set via ldflags at build time. Must be a variable, not a constant,
49
// because the linker can only modify variables at link time.
510
var version = "dev"
611

712
func Version() string { return version }
13+
14+
// UnsupportedTagMessage returns a user-facing error message for an unsupported image tag,
15+
// e.g. `unsupported image tag — try a tag like "2026.4" or "latest" in your config file`.
16+
func UnsupportedTagMessage() string {
17+
y, m, _ := time.Now().Date()
18+
m--
19+
if m == 0 {
20+
m, y = 12, y-1
21+
}
22+
return fmt.Sprintf("unsupported image tag — try a tag like %q or \"latest\" in your config file", fmt.Sprintf("%d.%d", y, int(m)))
23+
}

0 commit comments

Comments
 (0)