@@ -39,7 +39,7 @@ type DriverInterface = z.infer<typeof Data.DriverInterface>;
3939 * @version 4.1.0 - Production-ready with distinct() and aggregate()
4040 */
4141
42- import { Driver } from '@objectql/types' ;
42+ import { Driver , ObjectQLError } from '@objectql/types' ;
4343import { createClient , RedisClientType } from 'redis' ;
4444
4545/**
@@ -264,7 +264,7 @@ export class RedisDriver implements Driver {
264264 }
265265 }
266266
267- throw new Error ( `[RedisDriver] Failed to connect after ${ maxAttempts } attempts: ${ lastError ?. message } ` ) ;
267+ throw new ObjectQLError ( { code : 'DRIVER_CONNECTION_FAILED' , message : `[RedisDriver] Failed to connect after ${ maxAttempts } attempts: ${ lastError ?. message } ` } ) ;
268268 }
269269
270270 /**
@@ -399,7 +399,7 @@ export class RedisDriver implements Driver {
399399 const result = await this . client . set ( key , JSON . stringify ( doc ) , { NX : true } ) ;
400400
401401 if ( ! result ) {
402- throw new Error ( `Record with ID ${ id } already exists in ${ objectName } ` ) ;
402+ throw new ObjectQLError ( { code : 'DRIVER_QUERY_FAILED' , message : `Record with ID ${ id } already exists in ${ objectName } ` } ) ;
403403 }
404404
405405 return doc ;
@@ -415,7 +415,7 @@ export class RedisDriver implements Driver {
415415 const existing = await this . client . get ( key ) ;
416416
417417 if ( ! existing ) {
418- throw new Error ( `Record not found: ${ objectName } :${ id } ` ) ;
418+ throw new ObjectQLError ( { code : 'NOT_FOUND' , message : `Record not found: ${ objectName } :${ id } ` } ) ;
419419 }
420420
421421 const existingDoc = JSON . parse ( existing ) ;
@@ -806,7 +806,7 @@ export class RedisDriver implements Driver {
806806 switch ( command . type ) {
807807 case 'create' :
808808 if ( ! command . data ) {
809- throw new Error ( ' Create command requires data') ;
809+ throw new ObjectQLError ( { code : 'DRIVER_QUERY_FAILED' , message : ' Create command requires data' } ) ;
810810 }
811811 const created = await this . create ( command . object , command . data , cmdOptions ) ;
812812 return {
@@ -817,7 +817,7 @@ export class RedisDriver implements Driver {
817817
818818 case 'update' :
819819 if ( ! command . id || ! command . data ) {
820- throw new Error ( ' Update command requires id and data') ;
820+ throw new ObjectQLError ( { code : 'DRIVER_QUERY_FAILED' , message : ' Update command requires id and data' } ) ;
821821 }
822822 const updated = await this . update ( command . object , command . id , command . data , cmdOptions ) ;
823823 return {
@@ -828,7 +828,7 @@ export class RedisDriver implements Driver {
828828
829829 case 'delete' :
830830 if ( ! command . id ) {
831- throw new Error ( ' Delete command requires id') ;
831+ throw new ObjectQLError ( { code : 'DRIVER_QUERY_FAILED' , message : ' Delete command requires id' } ) ;
832832 }
833833 await this . delete ( command . object , command . id , cmdOptions ) ;
834834 return {
@@ -838,7 +838,7 @@ export class RedisDriver implements Driver {
838838
839839 case 'bulkCreate' :
840840 if ( ! command . records || ! Array . isArray ( command . records ) ) {
841- throw new Error ( ' BulkCreate command requires records array') ;
841+ throw new ObjectQLError ( { code : 'DRIVER_QUERY_FAILED' , message : ' BulkCreate command requires records array' } ) ;
842842 }
843843 // Use Redis PIPELINE for batch operations
844844 const pipeline = this . client . multi ( ) ;
@@ -868,7 +868,7 @@ export class RedisDriver implements Driver {
868868
869869 case 'bulkUpdate' :
870870 if ( ! command . updates || ! Array . isArray ( command . updates ) ) {
871- throw new Error ( ' BulkUpdate command requires updates array') ;
871+ throw new ObjectQLError ( { code : 'DRIVER_QUERY_FAILED' , message : ' BulkUpdate command requires updates array' } ) ;
872872 }
873873
874874 // First, batch GET all existing records using PIPELINE
@@ -917,7 +917,7 @@ export class RedisDriver implements Driver {
917917
918918 case 'bulkDelete' :
919919 if ( ! command . ids || ! Array . isArray ( command . ids ) ) {
920- throw new Error ( ' BulkDelete command requires ids array') ;
920+ throw new ObjectQLError ( { code : 'DRIVER_QUERY_FAILED' , message : ' BulkDelete command requires ids array' } ) ;
921921 }
922922 // Use Redis PIPELINE for batch operations
923923 const deletePipeline = this . client . multi ( ) ;
@@ -938,7 +938,7 @@ export class RedisDriver implements Driver {
938938 } ;
939939
940940 default :
941- throw new Error ( `Unknown command type: ${ ( command as any ) . type } ` ) ;
941+ throw new ObjectQLError ( { code : 'DRIVER_UNSUPPORTED_OPERATION' , message : `Unknown command type: ${ ( command as any ) . type } ` } ) ;
942942 }
943943 } catch ( error : any ) {
944944 return {
0 commit comments