Skip to content

Allowing custom asset id#1579

Merged
ehsandeep merged 1 commit intodevfrom
bugfix-custom-asset-id
Nov 7, 2025
Merged

Allowing custom asset id#1579
ehsandeep merged 1 commit intodevfrom
bugfix-custom-asset-id

Conversation

@Mzack9999
Copy link
Copy Markdown
Member

@Mzack9999 Mzack9999 commented Nov 6, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of invalid asset ID formats—the application now logs warnings and continues processing instead of halting on invalid asset IDs.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 6, 2025

Walkthrough

The SetAssetID method signature in the UploadWriter was changed from returning an error to returning nothing. Invalid asset IDs now trigger a warning log instead of returning an error. The corresponding call site in main.go no longer explicitly handles the (now absent) return value.

Changes

Cohort / File(s) Summary
Error Handling Refactor
internal/pdcp/writer.go
Removed error return from SetAssetID method; invalid asset IDs now log warning instead of returning error
Call Site Update
cmd/naabu/main.go
Removed explicit return value capture from writer.SetAssetID() call

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify that no other call sites in the codebase depend on the error return value from SetAssetID
  • Confirm that warning-level logging is the intended error handling strategy for invalid asset IDs

Poem

🐰 A method once strict, now gentler and kind,
Returns not an error, but logs in the mind,
From strict to a whisper, the path winds anew—
No crashes for warnings, just wisdom shines through! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Allowing custom asset id' is vague and doesn't clearly convey what the actual change accomplishes. The raw summary shows the change removes error handling from SetAssetID and converts warnings instead, which is more about error handling relaxation than 'allowing custom asset IDs'. Consider a more specific title like 'Change SetAssetID error handling to warnings' or 'Remove error return from SetAssetID' to better reflect the actual behavioral change in the code.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix-custom-asset-id

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Mzack9999 Mzack9999 marked this pull request as ready for review November 7, 2025 16:29
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d58b94 and 54f5d1a.

📒 Files selected for processing (2)
  • cmd/naabu/main.go (1 hunks)
  • internal/pdcp/writer.go (1 hunks)
🔇 Additional comments (1)
cmd/naabu/main.go (1)

159-162: Call site correctly updated for the new signature.

The removal of error handling here correctly reflects the updated SetAssetID signature. However, note that this means users who provide an invalid --asset-id flag will only receive a warning log (if they're watching) with no clear indication that their custom asset ID was rejected. See the concern raised in internal/pdcp/writer.go lines 100-105 regarding the validation behavior.

Comment on lines +100 to 105
func (u *UploadWriter) SetAssetID(id string) {
if !xidRegex.MatchString(id) {
return fmt.Errorf("invalid asset id provided")
gologger.Warning().Msgf("invalid asset id provided (unknown xid format): %s", id)
}
u.assetGroupID = id
return nil
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Inconsistent validation: warns about invalid asset IDs but still assigns them.

The method validates the asset ID format (line 101) and logs a warning if invalid (line 102), but then proceeds to assign the invalid ID anyway (line 104). This creates an inconsistent state where:

  1. The invalid asset ID will likely cause API failures when used in the PATCH endpoint URL (line 233: fmt.Sprintf(appendEndpoint, u.assetGroupID))
  2. Users receive only a warning that might be missed, with no way to handle the invalid input
  3. The PR title suggests "allowing custom asset id", but the strict regex validation (^[a-z0-9]{20}$) remains, creating confusion about the intended behavior

Recommended solutions:

  1. If the goal is to allow any custom asset ID: Remove the validation entirely and trust the server to handle invalid IDs.
  2. If validation is necessary: Don't assign invalid IDs—either keep the error return or set u.assetGroupID to an empty string (allowing the server to generate a new ID).

Apply this diff for solution 2 (recommended for backward compatibility):

 func (u *UploadWriter) SetAssetID(id string) {
 	if !xidRegex.MatchString(id) {
 		gologger.Warning().Msgf("invalid asset id provided (unknown xid format): %s", id)
+		return
 	}
 	u.assetGroupID = id
 }

This ensures invalid IDs are rejected early rather than causing cryptic API failures later.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (u *UploadWriter) SetAssetID(id string) {
if !xidRegex.MatchString(id) {
return fmt.Errorf("invalid asset id provided")
gologger.Warning().Msgf("invalid asset id provided (unknown xid format): %s", id)
}
u.assetGroupID = id
return nil
}
func (u *UploadWriter) SetAssetID(id string) {
if !xidRegex.MatchString(id) {
gologger.Warning().Msgf("invalid asset id provided (unknown xid format): %s", id)
return
}
u.assetGroupID = id
}
🤖 Prompt for AI Agents
In internal/pdcp/writer.go around lines 100 to 105, the method currently logs a
warning for invalid asset IDs but still assigns them; change it so invalid IDs
are not assigned to u.assetGroupID. Specifically, keep the regex check and
warning, but when the ID does not match, do not set u.assetGroupID — instead set
it to the empty string (so the server can generate an ID) and log the warning;
only assign id to u.assetGroupID when the regex passes.

@ehsandeep ehsandeep merged commit 5c80c2d into dev Nov 7, 2025
13 checks passed
@ehsandeep ehsandeep deleted the bugfix-custom-asset-id branch November 7, 2025 20:54
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