@@ -133,10 +133,46 @@ function mapCreateError(operationId: CliExposedOperationId, error: unknown, code
133133 return new CliError ( 'INVALID_ARGUMENT' , message , { operationId, details } ) ;
134134 }
135135
136- if ( code === 'TRACK_CHANGE_COMMAND_UNAVAILABLE' || code === 'CAPABILITY_UNAVAILABLE' ) {
136+ if ( code === 'TRACK_CHANGE_COMMAND_UNAVAILABLE' ) {
137137 return new CliError ( 'TRACK_CHANGE_COMMAND_UNAVAILABLE' , message , { operationId, details } ) ;
138138 }
139139
140+ if ( code === 'CAPABILITY_UNAVAILABLE' ) {
141+ const reason = ( details as { reason ?: string } | undefined ) ?. reason ;
142+ if ( reason === 'tracked_mode_unsupported' ) {
143+ return new CliError ( 'TRACK_CHANGE_COMMAND_UNAVAILABLE' , message , { operationId, details } ) ;
144+ }
145+ return new CliError ( 'COMMAND_FAILED' , message , { operationId, details } ) ;
146+ }
147+
148+ if ( code === 'COMMAND_UNAVAILABLE' ) {
149+ return new CliError ( 'COMMAND_FAILED' , message , { operationId, details } ) ;
150+ }
151+
152+ if ( error instanceof CliError ) return error ;
153+ return new CliError ( 'COMMAND_FAILED' , message , { operationId, details } ) ;
154+ }
155+
156+ function mapBlocksError ( operationId : CliExposedOperationId , error : unknown , code : string | undefined ) : CliError {
157+ const message = extractErrorMessage ( error ) ;
158+ const details = extractErrorDetails ( error ) ;
159+
160+ if ( code === 'TARGET_NOT_FOUND' ) {
161+ return new CliError ( 'TARGET_NOT_FOUND' , message , { operationId, details } ) ;
162+ }
163+
164+ if ( code === 'AMBIGUOUS_TARGET' || code === 'INVALID_TARGET' || code === 'INVALID_INPUT' ) {
165+ return new CliError ( 'INVALID_ARGUMENT' , message , { operationId, details } ) ;
166+ }
167+
168+ if ( code === 'CAPABILITY_UNAVAILABLE' ) {
169+ const reason = ( details as { reason ?: string } | undefined ) ?. reason ;
170+ if ( reason === 'tracked_mode_unsupported' ) {
171+ return new CliError ( 'TRACK_CHANGE_COMMAND_UNAVAILABLE' , message , { operationId, details } ) ;
172+ }
173+ return new CliError ( 'COMMAND_FAILED' , message , { operationId, details } ) ;
174+ }
175+
140176 if ( code === 'COMMAND_UNAVAILABLE' ) {
141177 return new CliError ( 'COMMAND_FAILED' , message , { operationId, details } ) ;
142178 }
@@ -170,6 +206,7 @@ const FAMILY_MAPPERS: Record<
170206 lists : mapListsError ,
171207 textMutation : mapTextMutationError ,
172208 create : mapCreateError ,
209+ blocks : mapBlocksError ,
173210 query : mapQueryError ,
174211 general : ( operationId , error ) => {
175212 if ( error instanceof CliError ) return error ;
@@ -272,6 +309,14 @@ export function mapFailedReceipt(operationId: CliExposedOperationId, result: unk
272309 return new CliError ( 'COMMAND_FAILED' , failureMessage , { operationId, failure } ) ;
273310 }
274311
312+ // Blocks family
313+ if ( family === 'blocks' ) {
314+ if ( failureCode === 'INVALID_TARGET' ) {
315+ return new CliError ( 'INVALID_ARGUMENT' , failureMessage , { operationId, failure } ) ;
316+ }
317+ return new CliError ( 'COMMAND_FAILED' , failureMessage , { operationId, failure } ) ;
318+ }
319+
275320 // Create family
276321 if ( family === 'create' ) {
277322 if ( failureCode === 'TRACK_CHANGE_COMMAND_UNAVAILABLE' ) {
0 commit comments