77 * output — pointer to output byte buffer
88 * length — length of output byte buffer
99 * measure — Clay text measurement callback
10+ * error_count, error_type, error_message_length, error_message_ptr
11+ * — per-render Clay error accessors
1012 */
1113
1214#include "clayterm.h"
3436
3537/* ── Instance state ───────────────────────────────────────────────── */
3638
39+ #define MAX_ERRORS 32
40+
3741struct Clayterm {
3842 int w , h ;
3943 Cell * front ;
@@ -44,6 +48,9 @@ struct Clayterm {
4448 /* clip region */
4549 int clipx , clipy , clipw , cliph ;
4650 int clipping ;
51+ /* error collection */
52+ Clay_ErrorData errors [MAX_ERRORS ];
53+ int error_count ;
4754};
4855
4956/* Memory layout inside the arena provided by the host:
@@ -399,7 +406,32 @@ int clayterm_size(int w, int h) {
399406 + align64 (clay_bytes ); /* Clay arena */
400407}
401408
402- static void clay_error (Clay_ErrorData err ) { (void )err ; }
409+ static void clay_error (Clay_ErrorData err ) {
410+ struct Clayterm * ct = (struct Clayterm * )err .userData ;
411+ if (ct -> error_count < MAX_ERRORS ) {
412+ ct -> errors [ct -> error_count ++ ] = err ;
413+ }
414+ }
415+
416+ int error_count (struct Clayterm * ct ) { return ct -> error_count ; }
417+
418+ int error_type (struct Clayterm * ct , int index ) {
419+ if (index < 0 || index >= ct -> error_count )
420+ return -1 ;
421+ return (int )ct -> errors [index ].errorType ;
422+ }
423+
424+ int error_message_length (struct Clayterm * ct , int index ) {
425+ if (index < 0 || index >= ct -> error_count )
426+ return 0 ;
427+ return ct -> errors [index ].errorText .length ;
428+ }
429+
430+ int error_message_ptr (struct Clayterm * ct , int index ) {
431+ if (index < 0 || index >= ct -> error_count )
432+ return 0 ;
433+ return (int )ct -> errors [index ].errorText .chars ;
434+ }
403435
404436struct Clayterm * init (void * mem , int w , int h ) {
405437 struct Clayterm * ct = (struct Clayterm * )mem ;
@@ -413,7 +445,7 @@ struct Clayterm *init(void *mem, int w, int h) {
413445 Clay_Arena arena =
414446 Clay_CreateArenaWithCapacityAndMemory (clay_bytes , clay_mem );
415447 Clay_Initialize (arena , (Clay_Dimensions ){(float )w , (float )h },
416- (Clay_ErrorHandler ){clay_error , 0 });
448+ (Clay_ErrorHandler ){clay_error , ct });
417449
418450 * ct = (struct Clayterm ){
419451 .w = w ,
@@ -437,6 +469,7 @@ struct Clayterm *init(void *mem, int w, int h) {
437469
438470void reduce (struct Clayterm * ct , uint32_t * buf , int len , int mode , int row ) {
439471 int i = 0 ;
472+ ct -> error_count = 0 ;
440473
441474 Clay_BeginLayout ();
442475
0 commit comments