@@ -506,12 +506,17 @@ export class TagError extends Error {
506506
507507 readonly original ?: Error ;
508508 readonly reason : TagErrorReason | undefined ;
509- readonly tag ?: string ;
509+ action ?: string ;
510+ tag ?: string ;
511+
512+ private static buildTagErrorMessage ( reason ?: TagErrorReason , tag ?: string , action ?: string ) : string {
513+ let baseMessage : string ;
514+ if ( action != null ) {
515+ baseMessage = `Unable to ${ action } tag ${ tag ? `'${ tag } '` : '' } ` ;
516+ } else {
517+ baseMessage = `Unable to perform action${ tag ? ` with tag '${ tag } '` : 'on tag' } ` ;
518+ }
510519
511- private static buildTagErrorMessage ( reason ?: TagErrorReason , tag ?: string , remote ?: string ) : string {
512- const baseMessage = `Unable to perform action${
513- tag ? ` with tag '${ tag } '${ remote ? ` on ${ remote } ` : '' } ` : 'on tag'
514- } `;
515520 switch ( reason ) {
516521 case TagErrorReason . TagAlreadyExists :
517522 return `${ baseMessage } because it already exists` ;
@@ -528,9 +533,9 @@ export class TagError extends Error {
528533 }
529534 }
530535
531- constructor ( reason ?: TagErrorReason , original ?: Error , tag ?: string , remote ?: string ) ;
536+ constructor ( reason ?: TagErrorReason , original ?: Error , tag ?: string , action ?: string ) ;
532537 constructor ( message ?: string , original ?: Error ) ;
533- constructor ( messageOrReason : string | TagErrorReason | undefined , original ?: Error , tag ?: string , remote ?: string ) {
538+ constructor ( messageOrReason : string | TagErrorReason | undefined , original ?: Error , tag ?: string , action ?: string ) {
534539 let reason : TagErrorReason | undefined ;
535540 if ( typeof messageOrReason !== 'string' ) {
536541 reason = messageOrReason as TagErrorReason ;
@@ -540,17 +545,25 @@ export class TagError extends Error {
540545 const message =
541546 typeof messageOrReason === 'string'
542547 ? messageOrReason
543- : TagError . buildTagErrorMessage ( messageOrReason as TagErrorReason , tag , remote ) ;
548+ : TagError . buildTagErrorMessage ( messageOrReason as TagErrorReason , tag , action ) ;
544549 super ( message ) ;
545550
546551 this . original = original ;
547552 this . reason = reason ;
548553 this . tag = tag ;
554+ this . action = action ;
549555 Error . captureStackTrace ?.( this , TagError ) ;
550556 }
551557
552558 WithTag ( tag : string ) {
553- this . message = TagError . buildTagErrorMessage ( this . reason , tag ) ;
559+ this . tag = tag ;
560+ this . message = TagError . buildTagErrorMessage ( this . reason , tag , this . action ) ;
561+ return this ;
562+ }
563+
564+ WithAction ( action : string ) {
565+ this . action = action ;
566+ this . message = TagError . buildTagErrorMessage ( this . reason , this . tag , action ) ;
554567 return this ;
555568 }
556569}
0 commit comments