@@ -527,10 +527,15 @@ export class LuaDebugSession extends LoggingDebugSession {
527
527
}
528
528
529
529
if ( typeof vars . length !== "undefined" && ! isMultiResult ) {
530
- const value : LuaDebug . Value = { type : "number" , value : vars . length . toString ( ) } ;
531
- variables . push ( this . buildVariable ( value , `#${ baseName } ` , tableLengthDisplayName ) ) ;
530
+ variables . push ( this . buildVariable ( vars . length , `#${ baseName } ` , tableLengthDisplayName ) ) ;
532
531
}
533
532
533
+ } else if ( vars . type === "error" ) {
534
+ response . success = false ;
535
+ response . message = this . filterErrorMessage ( vars . error ) ;
536
+ this . sendResponse ( response ) ;
537
+ return ;
538
+
534
539
} else {
535
540
response . success = false ;
536
541
}
@@ -648,8 +653,7 @@ export class LuaDebugSession extends LoggingDebugSession {
648
653
this . showOutput ( result . error , OutputCategory . Error ) ;
649
654
}
650
655
response . success = false ;
651
- const errorMsg = / ^ \[ .+ \] : \d + : ( .+ ) / . exec ( result . error ) ;
652
- response . message = ( errorMsg !== null && errorMsg . length > 1 ) ? errorMsg [ 1 ] : result . error ;
656
+ response . message = result . error ;
653
657
}
654
658
655
659
} else {
@@ -688,16 +692,15 @@ export class LuaDebugSession extends LoggingDebugSession {
688
692
} else if ( msg . results . length === 1 ) {
689
693
const result = msg . results [ 0 ] ;
690
694
const variablesReference = result . type === "table" ? this . variableHandles . create ( expression ) : 0 ;
691
- const value = result . value ?? `[${ result . type } ]` ;
692
- return { success : true , value, variablesReference} ;
695
+ return { success : true , value : this . getValueString ( result ) , variablesReference} ;
693
696
} else {
694
697
const variablesReference = this . variableHandles . create ( `@({${ expression } })` ) ;
695
- const value = `(${ msg . results . map ( r => r . value ?? `[ ${ r . type } ]` ) . join ( ", " ) } )` ;
698
+ const value = `(${ msg . results . map ( r => this . getValueString ( r ) ) . join ( ", " ) } )` ;
696
699
return { success : true , value, variablesReference} ;
697
700
}
698
701
699
702
} else if ( msg . type === "error" ) {
700
- return { success : false , error : msg . error } ;
703
+ return { success : false , error : this . filterErrorMessage ( msg . error ) } ;
701
704
702
705
} else {
703
706
return { success : false } ;
@@ -710,15 +713,15 @@ export class LuaDebugSession extends LoggingDebugSession {
710
713
let valueStr : string ;
711
714
let ref : number | undefined ;
712
715
if ( refName === "..." ) {
713
- valueStr = `(${ variable . value ?? "" } )` ;
716
+ valueStr = typeof variable . error !== "undefined"
717
+ ? `[error: ${ this . filterErrorMessage ( variable . error ) } ]`
718
+ : `(${ variable . value ?? "" } )` ;
714
719
ref = variable . type === "table" ? this . variableHandles . create ( "@({...})" ) : 0 ;
715
720
} else if ( variable . type === "table" ) {
716
- valueStr = variable . value ?? "[table]" ;
721
+ valueStr = this . getValueString ( variable ) ;
717
722
ref = this . variableHandles . create ( refName ) ;
718
- } else if ( typeof variable . value === "undefined" ) {
719
- valueStr = `[${ variable . type } ]` ;
720
723
} else {
721
- valueStr = variable . value ;
724
+ valueStr = this . getValueString ( variable ) ;
722
725
}
723
726
const name = typeof variableName !== "undefined" ? variableName : ( variable as LuaDebug . Variable ) . name ;
724
727
const indexedVariables = typeof variable . length !== "undefined" && variable . length > 0
@@ -739,6 +742,21 @@ export class LuaDebugSession extends LoggingDebugSession {
739
742
return value ;
740
743
}
741
744
745
+ private filterErrorMessage ( errorMsg : string ) {
746
+ const errorOnly = / ^ .+ : \d + : \s * ( .+ ) / . exec ( errorMsg ) ;
747
+ return ( errorOnly !== null && errorOnly . length > 1 ) ? errorOnly [ 1 ] : errorMsg ;
748
+ }
749
+
750
+ private getValueString ( value : LuaDebug . Value ) {
751
+ if ( typeof value . error !== "undefined" ) {
752
+ return `[error: ${ this . filterErrorMessage ( value . error ) } ]` ;
753
+ } else if ( typeof value . value !== "undefined" ) {
754
+ return value . value ;
755
+ } else {
756
+ return `[${ value . type } ]` ;
757
+ }
758
+ }
759
+
742
760
private resolvePath ( filePath : string ) {
743
761
if ( filePath . length === 0 ) {
744
762
return ;
@@ -804,7 +822,7 @@ export class LuaDebugSession extends LoggingDebugSession {
804
822
if ( resultMsg . type === "result" ) {
805
823
for ( const result of resultMsg . results ) {
806
824
if ( typeof result . value !== "undefined" ) {
807
- this . showOutput ( result . value , OutputCategory . Info ) ;
825
+ this . showOutput ( this . getValueString ( result ) , OutputCategory . Info ) ;
808
826
}
809
827
}
810
828
} else if ( resultMsg . type === "error" ) {
@@ -820,7 +838,7 @@ export class LuaDebugSession extends LoggingDebugSession {
820
838
if ( resultMsg . type === "result" ) {
821
839
for ( const result of resultMsg . results ) {
822
840
if ( typeof result . value !== "undefined" ) {
823
- this . showOutput ( result . value , OutputCategory . Info ) ;
841
+ this . showOutput ( this . getValueString ( result ) , OutputCategory . Info ) ;
824
842
}
825
843
}
826
844
} else if ( resultMsg . type === "error" ) {
0 commit comments