mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-15 09:01:31 +00:00
fix: disable embedlit
This commit is contained in:
@@ -118,6 +118,7 @@ linters:
|
||||
|
||||
modernize:
|
||||
disable:
|
||||
- embedlit # its fix promotes embedded fields into the outer literal, which does not compile
|
||||
- newexpr # don't replace aws.String() with new() — AWS SDK idiom
|
||||
- stringsbuilder # don't replace small string concatenations with strings.Builder
|
||||
|
||||
|
||||
@@ -182,8 +182,7 @@ func ImportablePools() ([]string, error) {
|
||||
// zpool exits non-zero when there is nothing to import, which is the
|
||||
// normal case. Anything else — no binary, no /dev/zfs — must surface, or
|
||||
// a machine with an existing pool looks empty to the caller.
|
||||
var exitErr *exec.ExitError
|
||||
if errors.As(err, &exitErr) {
|
||||
if _, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("zpool import: %w", err)
|
||||
|
||||
@@ -28,8 +28,7 @@ func execProbeRunner(ctx context.Context, name string, args ...string) (int, str
|
||||
if ctxErr := ctx.Err(); ctxErr != nil {
|
||||
return -1, out, ctxErr
|
||||
}
|
||||
var exitErr *exec.ExitError
|
||||
if errors.As(err, &exitErr) {
|
||||
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||
return exitErr.ExitCode(), out, nil
|
||||
}
|
||||
return -1, out, err
|
||||
|
||||
@@ -30,8 +30,7 @@ func runGate(t *testing.T, args ...string) (string, int) {
|
||||
if err == nil {
|
||||
return string(out), 0
|
||||
}
|
||||
var exitErr *exec.ExitError
|
||||
if errors.As(err, &exitErr) {
|
||||
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||
return string(out), exitErr.ExitCode()
|
||||
}
|
||||
t.Fatalf("running run-gate.sh: %v", err)
|
||||
|
||||
@@ -591,8 +591,7 @@ func resolveErrorDetail(err error) (code, message string, ok bool) {
|
||||
}
|
||||
text := err.Error()
|
||||
if _, exists := ErrorLookup[text]; exists {
|
||||
var cause *codedError
|
||||
if errors.As(err, &cause) {
|
||||
if cause, ok := errors.AsType[*codedError](err); ok {
|
||||
return text, cause.message, true
|
||||
}
|
||||
return text, "", true
|
||||
|
||||
@@ -231,8 +231,7 @@ func pumpConverseStream(ctx context.Context, fw *frameWriter, src converseStream
|
||||
event, ok, err := src.Next(ctx)
|
||||
if err != nil {
|
||||
excType := excInternalServerException
|
||||
var fault *streamFaultError
|
||||
if errors.As(err, &fault) {
|
||||
if _, ok := errors.AsType[*streamFaultError](err); ok {
|
||||
excType = excModelStreamErrorException
|
||||
}
|
||||
errCode = awserrors.ValidErrorCodeFromError(err)
|
||||
|
||||
@@ -124,8 +124,7 @@ func pumpInvokeStream(ctx context.Context, fw *frameWriter, src invokeStreamSour
|
||||
chunk, ok, err := src.Next(ctx)
|
||||
if err != nil {
|
||||
excType := excInternalServerException
|
||||
var fault *streamFaultError
|
||||
if errors.As(err, &fault) {
|
||||
if _, ok := errors.AsType[*streamFaultError](err); ok {
|
||||
excType = excModelStreamErrorException
|
||||
}
|
||||
errCode = awserrors.ValidErrorCodeFromError(err)
|
||||
|
||||
@@ -294,8 +294,7 @@ func isUsageCASConflict(err error) bool {
|
||||
if errors.Is(err, jetstream.ErrKeyExists) {
|
||||
return true
|
||||
}
|
||||
var apiErr *jetstream.APIError
|
||||
if errors.As(err, &apiErr) {
|
||||
if apiErr, ok := errors.AsType[*jetstream.APIError](err); ok {
|
||||
return apiErr.ErrorCode == jetstream.JSErrCodeStreamWrongLastSequence
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -94,7 +94,7 @@ func queryNodeCapacity(ctx context.Context, natsConn *nats.Conn, instanceType st
|
||||
}
|
||||
|
||||
// Random shuffle then stable-sort: fair distribution among equal-capacity nodes.
|
||||
rand.Shuffle(len(nodes), func(i, j int) {
|
||||
rand.Shuffle(len(nodes), func(i, j int) { //nolint:gosec // placement spread, not cryptographic
|
||||
nodes[i], nodes[j] = nodes[j], nodes[i]
|
||||
})
|
||||
sort.SliceStable(nodes, func(i, j int) bool {
|
||||
|
||||
@@ -254,8 +254,7 @@ func (reg *Registry) getBlob(ctx context.Context, w http.ResponseWriter, _, dige
|
||||
func (reg *Registry) startUpload(w http.ResponseWriter, r *http.Request, name string) {
|
||||
ctx := r.Context()
|
||||
if err := reg.requireRepo(ctx, name); err != nil {
|
||||
var mErr *ManifestStoreError
|
||||
if errors.As(err, &mErr) {
|
||||
if mErr, ok := errors.AsType[*ManifestStoreError](err); ok {
|
||||
WriteError(w, mErr.Status, mErr.Code, mErr.Msg)
|
||||
return
|
||||
}
|
||||
@@ -593,8 +592,7 @@ func (reg *Registry) putManifest(w http.ResponseWriter, r *http.Request, name, r
|
||||
|
||||
digest, err := reg.StoreManifest(ctx, reg.AccountID, name, reference, r.Header.Get("Content-Type"), body)
|
||||
if err != nil {
|
||||
var mErr *ManifestStoreError
|
||||
if errors.As(err, &mErr) {
|
||||
if mErr, ok := errors.AsType[*ManifestStoreError](err); ok {
|
||||
WriteError(w, mErr.Status, mErr.Code, mErr.Msg)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -385,8 +385,7 @@ func (gw *GatewayConfig) ecrListImages(ctx context.Context, accountID, repo stri
|
||||
// mapStoreManifestError translates the OCI manifest-store error codes into AWS
|
||||
// PutImage error codes.
|
||||
func mapStoreManifestError(ctx context.Context, err error, repo string) error {
|
||||
var mErr *gateway_ecr.ManifestStoreError
|
||||
if errors.As(err, &mErr) {
|
||||
if mErr, ok := errors.AsType[*gateway_ecr.ManifestStoreError](err); ok {
|
||||
switch mErr.Code {
|
||||
case "DIGEST_INVALID":
|
||||
return errors.New(awserrors.ErrorImageDigestDoesNotMatch)
|
||||
|
||||
@@ -203,8 +203,7 @@ func isZoneLockHeld(err error) bool {
|
||||
if errors.Is(err, jetstream.ErrKeyExists) {
|
||||
return true
|
||||
}
|
||||
var apiErr *jetstream.APIError
|
||||
if errors.As(err, &apiErr) {
|
||||
if apiErr, ok := errors.AsType[*jetstream.APIError](err); ok {
|
||||
return apiErr.ErrorCode == jetstream.JSErrCodeStreamWrongLastSequence
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -677,7 +677,7 @@ func (s *EKSServiceImpl) selectWorkerHost(ctx context.Context, instanceType stri
|
||||
counts[host]++
|
||||
}
|
||||
}
|
||||
rand.Shuffle(len(hosts), func(i, j int) { hosts[i], hosts[j] = hosts[j], hosts[i] })
|
||||
rand.Shuffle(len(hosts), func(i, j int) { hosts[i], hosts[j] = hosts[j], hosts[i] }) //nolint:gosec // worker spread, not cryptographic
|
||||
best := hosts[0]
|
||||
for _, h := range hosts[1:] {
|
||||
if counts[h] < counts[best] {
|
||||
|
||||
@@ -121,8 +121,7 @@ func isCASConflict(err error) bool {
|
||||
if errors.Is(err, jetstream.ErrKeyExists) {
|
||||
return true
|
||||
}
|
||||
var apiErr *jetstream.APIError
|
||||
if errors.As(err, &apiErr) {
|
||||
if apiErr, ok := errors.AsType[*jetstream.APIError](err); ok {
|
||||
return apiErr.ErrorCode == jetstream.JSErrCodeStreamWrongLastSequence
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -407,7 +407,7 @@ func TestGenerateInstanceTypes_BurstableFlag(t *testing.T) {
|
||||
|
||||
for name, info := range broadwellTypes {
|
||||
isBurstable := strings.HasPrefix(name, "t")
|
||||
family := strings.SplitN(name, ".", 2)[0]
|
||||
family, _, _ := strings.Cut(name, ".")
|
||||
assert.Equal(t, isBurstable, *info.BurstablePerformanceSupported,
|
||||
"%s burstable flag mismatch", name)
|
||||
assert.Equal(t, !prevGen[family], *info.CurrentGeneration,
|
||||
|
||||
@@ -115,8 +115,7 @@ func ErrorCode(err error) string {
|
||||
if err == nil {
|
||||
return ""
|
||||
}
|
||||
var awsErr awserr.Error
|
||||
if errors.As(err, &awsErr) {
|
||||
if awsErr, ok := errors.AsType[awserr.Error](err); ok {
|
||||
return awsErr.Code()
|
||||
}
|
||||
if errors.Is(err, ErrShed) {
|
||||
|
||||
@@ -91,7 +91,7 @@ func (r *NATSConfVersionReader) ReadVersion(path string) (int, error) {
|
||||
}
|
||||
|
||||
// Check first line only.
|
||||
firstLine := strings.SplitN(string(data), "\n", 2)[0]
|
||||
firstLine, _, _ := strings.Cut(string(data), "\n")
|
||||
match := natsVersionRe.FindStringSubmatch(firstLine)
|
||||
if match == nil {
|
||||
return 0, nil // no version marker
|
||||
|
||||
@@ -165,8 +165,7 @@ func (p *GatewayClaimProber) GatewayReachable(ctx context.Context, gwIP string)
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "ping", "-c", "1", "-W", "1", gwIP)
|
||||
if err := cmd.Run(); err != nil {
|
||||
var exitErr *exec.ExitError
|
||||
if errors.As(err, &exitErr) {
|
||||
if _, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||
return false, nil
|
||||
}
|
||||
return false, fmt.Errorf("ping %s: %w", gwIP, err)
|
||||
|
||||
@@ -148,8 +148,7 @@ func (s *S3ObjectStore) EnsureBucket(ctx context.Context, bucket string) error {
|
||||
}
|
||||
_, err := s.client.CreateBucketWithContext(ctx, &s3.CreateBucketInput{Bucket: aws.String(bucket)})
|
||||
if err != nil {
|
||||
var aerr awserr.Error
|
||||
if errors.As(err, &aerr) {
|
||||
if aerr, ok := errors.AsType[awserr.Error](err); ok {
|
||||
switch aerr.Code() {
|
||||
case s3.ErrCodeBucketAlreadyOwnedByYou, s3.ErrCodeBucketAlreadyExists:
|
||||
return nil
|
||||
|
||||
@@ -111,7 +111,7 @@ func TestRenderedConfig_HasMigrationVersionMarker(t *testing.T) {
|
||||
raw, err := os.ReadFile(templatePath(t))
|
||||
require.NoError(t, err)
|
||||
|
||||
firstLine := strings.SplitN(string(raw), "\n", 2)[0]
|
||||
firstLine, _, _ := strings.Cut(string(raw), "\n")
|
||||
assert.Equal(t, "# spinifex-config-version: 3", firstLine,
|
||||
"nats.conf template must start with the current migration version marker")
|
||||
}
|
||||
|
||||
@@ -246,8 +246,7 @@ var localSystemID = func() (string, error) {
|
||||
out, err := sudoCommand("ovs-vsctl", "get", "open_vswitch", ".", "external-ids:system-id").Output()
|
||||
if err != nil {
|
||||
var stderr string
|
||||
var exitErr *exec.ExitError
|
||||
if errors.As(err, &exitErr) {
|
||||
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||
stderr = strings.TrimSpace(string(exitErr.Stderr))
|
||||
}
|
||||
return "", fmt.Errorf("ovs-vsctl get system-id: %s: %w", stderr, err)
|
||||
@@ -274,8 +273,7 @@ var discoverChassis = func(sbAddr string) ([]string, error) {
|
||||
out, err := sudoCommand("ovn-sbctl", args...).Output()
|
||||
if err != nil {
|
||||
var stderr string
|
||||
var exitErr *exec.ExitError
|
||||
if errors.As(err, &exitErr) {
|
||||
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||
stderr = strings.TrimSpace(string(exitErr.Stderr))
|
||||
}
|
||||
return nil, fmt.Errorf("ovn-sbctl list Chassis: %s: %w", stderr, err)
|
||||
@@ -992,8 +990,7 @@ var portToBr = func(port string) (string, error) {
|
||||
out, err := sudoCommand("ovs-vsctl", "port-to-br", port).Output()
|
||||
if err != nil {
|
||||
var stderr string
|
||||
var exitErr *exec.ExitError
|
||||
if errors.As(err, &exitErr) {
|
||||
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||
stderr = strings.TrimSpace(string(exitErr.Stderr))
|
||||
}
|
||||
return "", fmt.Errorf("ovs-vsctl port-to-br %s: %s: %w", port, stderr, err)
|
||||
|
||||
@@ -21,8 +21,7 @@ func errCodeMessage(err error) (code, message string) {
|
||||
if err == nil {
|
||||
return "", ""
|
||||
}
|
||||
var aerr awserr.Error
|
||||
if errors.As(err, &aerr) {
|
||||
if aerr, ok := errors.AsType[awserr.Error](err); ok {
|
||||
return aerr.Code(), aerr.Message()
|
||||
}
|
||||
return "non-aws-error", err.Error()
|
||||
|
||||
Reference in New Issue
Block a user