You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement Named Error Objects System for Image Customizer (#324)
This PR implements a comprehensive named error objects system for the
Image Customizer to improve error telemetry and provide organized error
messages for users.
## Key Changes
**Named Error Objects Pattern**
- Replaced centralized error categories and codes with locally-defined
named error objects
- Each error is defined in the file where it's used with descriptive
names like `ErrCannotSetUidOnExistingUser`
- Error objects follow the pattern:
`NewImageCustomizerError("Module:ErrorType", "error message")`
**Error Message Transformation**
Updated all error handling to use proper wrapping patterns:
```go
// Before
return fmt.Errorf("cannot set UID (%d) on a user (%s) that already exists", *user.UID, user.Name)
// After
var ErrCannotSetUidOnExistingUser = NewImageCustomizerError("Users:SetUidOnExistingUser", "cannot set UID on a user that already exists")
return fmt.Errorf("%w (UID='%d', user='%s')", ErrCannotSetUidOnExistingUser, *user.UID, user.Name)
```
**Telemetry Integration**
- Simplified telemetry to only record `error.name` in span attributes
- The deepest ImageCustomizerError in the error chain is used for the
error name in the span
**Test Compatibility**
- Updated error object messages to align with existing test expectations
- Ensured error messages match patterns expected by
`assert.ErrorContains()` calls
**Comprehensive Coverage**
The system now covers all leaf errors across the entire
imagecustomizerlib package, including:
- Image processing and format conversion errors
- Input/output validation errors
- OS customization errors (packages, services, users, groups, etc.)
- Verity and security feature errors
- Environment and configuration validation errors
The system maintains full functionality while providing better error
categorization for telemetry and more descriptive error messages for end
users.
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: Adit Jha <[email protected]>
Co-authored-by: Adit Jha <[email protected]>
ErrArtifactInjectFilesPathResolution=NewImageCustomizerError("Artifacts:InjectFilesPathResolution", "failed to get absolute path of inject-files.yaml")
41
+
ErrArtifactInjectFilesImageConnection=NewImageCustomizerError("Artifacts:InjectFilesImageConnection", "failed to connect to image file to inject files")
42
+
ErrArtifactInjectFilesPartitionMount=NewImageCustomizerError("Artifacts:InjectFilesPartitionMount", "failed to mount partition for file injection")
43
+
ErrArtifactPartitionUnmount=NewImageCustomizerError("Artifacts:PartitionUnmount", "failed to cleanly unmount partition")
44
+
ErrArtifactCosiImageConversion=NewImageCustomizerError("Artifacts:CosiImageConversion", "failed to convert customized raw image to cosi output format")
45
+
ErrArtifactOutputImageConversion=NewImageCustomizerError("Artifacts:OutputImageConversion", "failed to convert customized raw image to output format")
46
+
ErrArtifactImageConnectionForExtraction=NewImageCustomizerError("Artifacts:ImageConnectionForExtraction", "failed to connect to image")
47
+
ErrArtifactImageConnectionClose=NewImageCustomizerError("Artifacts:ImageConnectionClose", "failed to cleanly close image connection")
48
+
ErrArtifactReleaseFileRead=NewImageCustomizerError("Artifacts:ReleaseFileRead", "failed to read release file")
49
+
ErrArtifactImageUuidNotFound=NewImageCustomizerError("Artifacts:ImageUuidNotFound", "IMAGE_UUID not found in release file")
50
+
ErrArtifactImageUuidParse=NewImageCustomizerError("Artifacts:ImageUuidParse", "failed to parse IMAGE_UUID")
0 commit comments