Skip to content

Conversation

@zoonderkins
Copy link

@zoonderkins zoonderkins commented Oct 20, 2025

Summary

This PR fixes the critical bug reported in #47 where the cntb cancel objectStorage command was failing with a panic error.

Screenshot 2025-10-20 at 18 31 45

Problem

When attempting to cancel an object storage using:

cntb cancel objectStorage 4c4bd92c-0654-4848-ab87-3c04ec0e27dd

The command failed with:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x48 pc=0x100bbcf00]

And after fixing the panic, it failed with:

ERROR Error while canceling the object storage: cancelObjectStorageRequest is required and must be specified

Root Causes

This PR addresses three critical issues:

1. Missing API Request Body

Both objectStorage cancel and instance cancel commands were missing the required request body parameter:

  • The API requires a CancelObjectStorageRequest or CancelInstanceRequest object
  • The commands were calling the API without providing this required parameter
  • Fix: Added CancelObjectStorageRequest and CancelInstanceRequest initialization

2. Variable Name Typo

The objectStorage cancel command had a typo in the variable name:

  • Variable was named cancelbjectStorageId (missing the letter 'O')
  • Fix: Renamed to cancelObjectStorageId in both cancel.go and vars.go

3. Nil Pointer Dereference

The error handler was accessing httpResp.Body without checking if httpResp is nil:

  • When API calls fail due to network errors, httpResp can be nil
  • Fix: Added nil check before accessing httpResp.Body in handleErrors()

Changes

  • cmd/objectStorage/cancel.go: Add request body initialization and fix variable name
  • cmd/objectStorage/vars.go: Fix variable name typo
  • cmd/instances/cancel.go: Add request body initialization
  • cmd/util/handleErrors.go: Add nil pointer check for httpResp

Testing

Tested successfully with:

./cntb cancel objectStorage 4c4bd92c-0654-4848-ab87-3c04ec0e27dd

Result:

TENANTID  CUSTOMERID  OBJECTSTORAGEID                       DISPLAYNAME  CANCELDATE  
  INT       13094617    4c4bd92c-0654-4848-ab87-3c04ec0e27dd  idrive       2025-10-24
Screenshot 2025-10-20 at 18 21 43 Screenshot 2025-10-20 at 18 31 17

Compilation successful with no errors

Impact

  • ✅ Fixes objectStorage cancel command (Issue Cannot delete s3 storage #47)
  • ✅ Fixes instance cancel command (same issue)
  • ✅ Improves error handling for all API commands (nil pointer protection)
  • ✅ No breaking changes
  • ✅ Backward compatible

Checklist

  • Code compiles without errors
  • Tested with real API calls
  • Fixed all identified issues
  • No breaking changes introduced
  • Error handling improved

Fixes #47


Pull Request opened by Augment Code with guidance from the PR author

…abo#47)

This commit fixes three critical issues that prevented the cancel commands from working:

1. Missing API Request Body: Both objectStorage and instance cancel commands
   were missing the required CancelRequest body parameter, causing API errors.
   - Added CancelObjectStorageRequest for objectStorage cancel
   - Added CancelInstanceRequest for instance cancel

2. Variable Name Typo: Fixed typo in objectStorage cancel command
   - Changed cancelbjectStorageId to cancelObjectStorageId (missing O)
   - Updated in cancel.go and vars.go

3. Nil Pointer Dereference: Fixed panic in error handler when httpResp is nil
   - Added nil check before accessing httpResp.Body in handleErrors()
   - Prevents crash on network errors or connection failures

Changes:
- cmd/objectStorage/cancel.go: Add request body and fix variable name
- cmd/objectStorage/vars.go: Fix variable name typo
- cmd/instances/cancel.go: Add request body
- cmd/util/handleErrors.go: Add nil pointer check

Tested with: cntb cancel objectStorage 4c4bd92c-0654-4848-ab87-3c04ec0e27dd
Result: Successfully cancelled with cancelDate 2025-10-24

Fixes contabo#47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot delete s3 storage

1 participant