Skip to content

v0.1.4: Fix type validation and improve error messages

Choose a tag to compare

@jackielii jackielii released this 31 Oct 20:14
· 140 commits to main since this release

What's Changed

Bug Fixes

  • Prevent panics from reflect.Call: Added comprehensive type validation to check both argument count and type compatibility before calling functions via reflection
  • Improved error messages: Error messages now include full context with page names, function paths, and specific type mismatch details

Error Message Improvements

Before:

error executing render operation: argument 1: type string not assignable to parameter type int

After:

error rendering component on page argsComponentTestPage: function github.com/jackielii/structpages.standaloneComponentFunc: argument 1 has type string, expected int

Technical Details

  • Added formatCallable() helper function to extract human-readable function names using runtime.FuncForPC
  • Type validation now checks IsValid() and AssignableTo() for all arguments before calling
  • Enhanced error context to include page name when available
  • Added TestRenderComponent_TypeMismatch test to verify type validation

Files Changed

  • reflect.go: Added formatCallable() helper
  • struct_pages_render_component.go: Enhanced validation and error messages in executeRenderOp and handleRenderComponentError
  • struct_pages_test.go: Added type mismatch test and updated existing tests
  • render_page_component_test.go: Updated test assertions for new error messages

Full Changelog: v0.1.3...v0.1.4