Skip to content

fix(instance): avoid index out of range in server type deprecation warning#5716

Closed
SAY-5 wants to merge 5 commits into
scaleway:mainfrom
SAY-5:fix-server-type-deprecation-panic
Closed

fix(instance): avoid index out of range in server type deprecation warning#5716
SAY-5 wants to merge 5 commits into
scaleway:mainfrom
SAY-5:fix-server-type-deprecation-panic

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jun 17, 2026

Copy link
Copy Markdown

warningServerTypeDeprecated builds its warnings with make([]string, 0, 2) and then assigns warning[0] = ..., which panics with index out of range [0] with length 0 because the slice has length 0. Running scw instance server get <id> against a server whose type is deprecated hits this and crashes the CLI.

Switched the first element to append so the slice grows correctly, which keeps the later early-return paths intact. Added a test that exercises the function with an unreachable client so it returns early without panicking.

Fixes #5682.

…rning

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@SAY-5 SAY-5 requested review from a team and remyleone as code owners June 17, 2026 19:31
@SAY-5 SAY-5 changed the base branch from master to main June 17, 2026 19:32
@github-actions github-actions Bot added the instance Instance issues, bugs and feature requests label Jun 17, 2026
@remyleone remyleone requested a review from Copilot June 17, 2026 20:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a CLI crash in the Instance namespace when emitting the “server type deprecated” warning by ensuring the warnings slice grows correctly instead of indexing into a zero-length slice (panic seen in scw instance server get <id> for EndOfService servers).

Changes:

  • Fix warningServerTypeDeprecated slice construction to avoid index out of range panics.
  • Add a regression test for warningServerTypeDeprecated to ensure early-return paths don’t panic.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/namespaces/instance/v1/helpers_types.go Replaces invalid warning[0] = ... assignment with append(...) to prevent a panic.
internal/namespaces/instance/v1/helpers_types_test.go Adds a regression test covering the no-panic / early-return behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3 to +29
import (
"context"
"testing"

instance "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestWarningServerTypeDeprecated(t *testing.T) {
// Point the client at an unreachable endpoint so the catalog and
// compatible-types lookups fail and the function returns early.
client, err := scw.NewClient(
scw.WithAuth("SCWXXXXXXXXXXXXXXXXX", "11111111-1111-1111-1111-111111111111"),
scw.WithAPIURL("http://127.0.0.1:1"),
scw.WithDefaultZone(scw.ZoneFrPar1),
scw.WithDefaultRegion(scw.RegionFrPar),
)
require.NoError(t, err)

server := &instance.Server{CommercialType: "DEV1-S", Zone: scw.ZoneFrPar1}
warnings := warningServerTypeDeprecated(context.Background(), client, server)

require.NotEmpty(t, warnings)
assert.Contains(t, warnings[0], "EndOfService")
}
@codecov-commenter

codecov-commenter commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.70%. Comparing base (29e5bab) to head (98b45ee).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5716      +/-   ##
==========================================
+ Coverage   50.67%   50.70%   +0.03%     
==========================================
  Files         340      340              
  Lines       78101    78101              
==========================================
+ Hits        39577    39605      +28     
+ Misses      37028    37000      -28     
  Partials     1496     1496              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@remyleone

Copy link
Copy Markdown
Member

Thanks a lot :) I think #5683 already handles this issue let us know once it is merged if it solved your problem

@remyleone remyleone closed this Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

instance Instance issues, bugs and feature requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runtime error: index out of range (warningServerTypeDeprecated)

4 participants