File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,6 +87,9 @@ export async function cppRunFiles(
8787 filenames : string [ ] ,
8888 onOutput : ( output : ReplOutput ) => void
8989) : Promise < string > {
90+ // Constants for stack trace processing
91+ const WANDBOX_PATH = "/home/wandbox" ;
92+
9093 // Track state for processing stack traces
9194 let inStackTrace = false ;
9295 let foundSignal = false ;
@@ -125,10 +128,10 @@ export async function cppRunFiles(
125128 // Process stack trace lines
126129 if ( inStackTrace && ndjsonType === "StdErr" ) {
127130 // Filter to show only user source code
128- if ( output . message . includes ( "/home/wandbox" ) ) {
131+ if ( output . message . includes ( WANDBOX_PATH ) ) {
129132 onOutput ( {
130133 type : "trace" ,
131- message : output . message . replace ( "/home/wandbox /", "" ) ,
134+ message : output . message . replace ( WANDBOX_PATH + " /", "" ) ,
132135 } ) ;
133136 }
134137 return ;
Original file line number Diff line number Diff line change @@ -33,6 +33,11 @@ export async function rustRunFiles(
3333 filenames : string [ ] ,
3434 onOutput : ( output : ReplOutput ) => void
3535) : Promise < string > {
36+ // Regular expressions for parsing stack traces
37+ const STACK_FRAME_PATTERN = / ^ \s * \d + : / ;
38+ const LOCATION_PATTERN = / ^ \s * a t .\/ / ;
39+ const SYSTEM_CODE_PATTERN = / ^ \s * a t .\/ p r o g .r s / ;
40+
3641 // Track state for processing panic traces
3742 let inPanicHook = false ;
3843 let foundBacktraceHeader = false ;
@@ -79,12 +84,12 @@ export async function rustRunFiles(
7984 if ( foundBacktraceHeader ) {
8085 // Process stack trace lines
8186 // Look for pattern: " N: ..." followed by " at ./file.rs:line"
82- if ( / ^ \s * \d + : / . test ( output . message ) ) {
87+ if ( STACK_FRAME_PATTERN . test ( output . message ) ) {
8388 traceLines . push ( output . message ) ;
84- } else if ( / ^ \s * a t . \/ / . test ( output . message ) ) {
89+ } else if ( LOCATION_PATTERN . test ( output . message ) ) {
8590 if ( traceLines . length > 0 ) {
8691 // Check if this is user code (not prog.rs)
87- if ( ! / ^ \s * a t . \/ p r o g . r s / . test ( output . message ) ) {
92+ if ( ! SYSTEM_CODE_PATTERN . test ( output . message ) ) {
8893 onOutput ( {
8994 type : "trace" ,
9095 message : traceLines [ traceLines . length - 1 ] . replace ( "prog::" , "" ) ,
You can’t perform that action at this time.
0 commit comments