feat(generate): improve mapping between single err return results and template data#59
Conversation
Pull Request Review: Error-Only Return Type SupportSummaryThis PR adds support for handler methods that return only an error (Pattern 4), enabling health check and webhook-style endpoints. The implementation is well-designed and follows the existing codebase patterns effectively. ✅ Strengths
🔍 Code Quality ObservationsPotential Issue: Type Assertion Panic RiskLocation: X: &ast.TypeAssertExpr{
X: ast.NewIdent(errIdent),
Type: errTypeExpr,
},Issue: This generates a type assertion without the Example Scenario: type StatusErr interface {
error
StatusCode() int
}
func (s Server) Healthcheck(ctx context.Context) StatusErr {
// Returns a different error type at runtime
return fmt.Errorf("database connection failed")
}At compile time, Suggested Fix: if errWithCode, ok := err.(StatusErr); ok {
data.ErrStatusCode = errWithCode.StatusCode()
} else {
data.ErrStatusCode = 500
}This would require checking both the declared return type AND generating safe runtime code. Minor: Comment FormattingLocation: Some comments are missing the space after // Pattern 4: Error Only - use struct{} as result type // ✅ Good
/ Pattern 4: Error Only - use struct{} as result type // ❌ Bad (missing //)This appears to be a rendering issue in the diff. Please verify these are proper comments in the actual code. 🎯 Suggestions
🔒 Security Considerations✅ No security concerns identified. The generated code:
⚡ Performance Considerations✅ No performance concerns:
📋 Test CoverageCovered:
Not Covered (consider adding):
✅ Checklist CompliancePer
🎬 RecommendationAPPROVE with minor fixes suggested This is a solid feature addition that extends Muxt's capabilities in a clean, type-safe manner. The main concern is the potential panic from the type assertion. Consider either:
The implementation quality is high and follows the project's architectural patterns well. Questions for Author:
|
No description provided.