Skip to content

Fix tagging is error#6681

Merged
hkantare merged 5 commits intoIBM-Cloud:masterfrom
stefano-rm:fix_tagging_isError
Mar 2, 2026
Merged

Fix tagging is error#6681
hkantare merged 5 commits intoIBM-Cloud:masterfrom
stefano-rm:fix_tagging_isError

Conversation

@stefano-rm
Copy link
Copy Markdown
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates OR Closes #0000

Output from acceptance testing:

Summary

This PR enhances error handling in the resource tagging functionality and updates the platform-services-go-sdk dependency to v0.94.3. The main improvement is that error messages now include detailed information from all result fields (resource_id, is_error, and message) instead of only showing failed items, providing better debugging capabilities for users.

Changes

1. Enhanced Error Handling in Resource Tagging

File: ibm/service/globaltagging/resource_ibm_resource_tag.go

  • Replaced error collection array approach with a more efficient boolean flag (hasErrors)
  • Improved error output format to include all results (not just failed ones) for better debugging
  • Added JSON marshalling for both results.Results and fullResponse to provide comprehensive error information
  • Optimized error checking to break on first error found (performance improvement)

Before:

errMap := make([]globaltaggingv1.TagResultsItem, 0)
for _, res := range results.Results {
    if res.IsError != nil && *res.IsError {
        errMap = append(errMap, res)
    }
}
if len(errMap) > 0 {
    output, _ := json.MarshalIndent(errMap, "", "    ")
    return diag.FromErr(flex.FmtErrorf("Error while creating tag: %s - Full response: %s", string(output), fullResponse))
}

After:

hasErrors := false
for _, res := range results.Results {
    if res.IsError != nil && *res.IsError {
        hasErrors = true
        break
    }
}
if hasErrors {
    resultsJSON, _ := json.MarshalIndent(results.Results, "", "    ")
    fullResponseJSON, _ := json.MarshalIndent(fullResponse, "", "    ")
    return diag.FromErr(flex.FmtErrorf("Error while creating tag: %s - Full response: %s", string(resultsJSON), string(fullResponseJSON)))
}
  1. Updated Test to Verify Enhanced Error Format
    File: ibm/service/globaltagging/resource_ibm_resource_tag_test.go

Updated TestAccResourceTag_FakeCrnExpectingError to verify that error output includes the message field:

// Before
ExpectError: regexp.MustCompile("\"is_error\": true"),

// After
ExpectError: regexp.MustCompile(`(?s)"is_error":\s*true.*"message":`),

The regex now:

Uses (?s) flag to handle multiline JSON output
Verifies presence of both is_error and message fields
Ensures the enhanced error format is working correctly
3. Dependency Update
Files: go.mod, go.sum

Updated github.com/IBM/platform-services-go-sdk from v0.94.2 to v0.94.3
Cleaned up unused indirect dependencies via go mod tidy
Benefits
Better Debugging: Error messages now show complete operation results with detailed messages, not just failures
Performance: Early exit on first error instead of iterating through all results
Maintainability: Cleaner, more readable code
SDK Alignment: Updated to latest platform-services-go-sdk version
Example Error Output
Before (only failed items):

[
    {
        "resource_id": "crn:v1:...",
        "is_error": true
    }
]

After (all results with message):

[
    {
        "resource_id": "crn:v1:staging:public:cloud-object-storage:global:a/d99e99999dfe99ee999999f99bddd099:ab99d9be-9e9c-99dd-ad99-9bced9999999::",
        "is_error": true,
        "message": "The provided CRN crn:v1:staging:public:cloud-object-storage:global:a/d99e99999dfe99ee999999f99bddd099:ab99d9be-9e9c-99dd-ad99-9bced9999999:: is not valid for the target Cloud bluemix"
    }
]

Testing
Code Quality Checks
All checks passed:

$ go version
go version go1.25.7 darwin/arm64

$ go vet ./ibm/service/globaltagging/
# No errors ✅

$ go build -o /dev/null ./ibm/service/globaltagging/
# Build successful ✅

Output from acceptance testing:
$ cd ibm/service/globaltagging
$ TF_ACC=1 go test -v -run=TestAccResourceTag_FakeCrnExpectingError -timeout 10m

=== RUN   TestAccResourceTag_FakeCrnExpectingError
--- PASS: TestAccResourceTag_FakeCrnExpectingError (7.78s)
PASS
ok  	github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/globaltagging	10.767s

Test validates:

✅ Error output includes "is_error": true
✅ Error output includes "message" field with detailed error information
✅ Enhanced error format provides better debugging information for users
Breaking Changes
None - changes are backward compatible

@stefano-rm
Copy link
Copy Markdown
Contributor Author

BEFORE
image (28)

AFTER
AFTER

@hkantare hkantare merged commit babfb93 into IBM-Cloud:master Mar 2, 2026
1 check passed
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.

2 participants