@@ -92,12 +92,24 @@ function flushOutput() {
9292 stderrBuffer = "" ;
9393}
9494
95- function formatRubyError ( error ) {
95+ function formatRubyError ( error , isFile ) {
9696 if ( ! ( error instanceof Error ) ) {
9797 return `予期せぬエラー: ${ String ( error ) . trim ( ) } ` ;
9898 }
9999
100- return error . message ;
100+ let errorMessage = error . message ;
101+
102+ // Clean up Ruby error messages by filtering out internal eval lines
103+ if ( errorMessage . includes ( "Traceback" ) || errorMessage . includes ( "Error" ) ) {
104+ let lines = errorMessage . split ( "\n" ) ;
105+ lines = lines . filter ( ( line ) => line !== "-e:in 'Kernel.eval'" ) ;
106+ if ( isFile ) {
107+ lines = lines . filter ( ( line ) => ! line . startsWith ( "eval:1:in" ) ) ;
108+ }
109+ errorMessage = lines . join ( "\n" ) ;
110+ }
111+
112+ return errorMessage ;
101113}
102114
103115async function runCode ( id , payload ) {
@@ -131,7 +143,7 @@ async function runCode(id, payload) {
131143
132144 rubyOutput . push ( {
133145 type : "error" ,
134- message : formatRubyError ( e ) ,
146+ message : formatRubyError ( e , false ) ,
135147 } ) ;
136148 }
137149
@@ -168,12 +180,7 @@ async function runFile(id, payload) {
168180 }
169181
170182 // Run the specified file
171- const fileContent = files [ name ] ;
172- if ( ! fileContent ) {
173- throw new Error ( `File not found: ${ name } ` ) ;
174- }
175-
176- rubyVM . eval ( fileContent ) ;
183+ rubyVM . eval ( `load ${ JSON . stringify ( name ) } ` ) ;
177184
178185 // Flush any buffered output
179186 flushOutput ( ) ;
@@ -183,7 +190,7 @@ async function runFile(id, payload) {
183190
184191 rubyOutput . push ( {
185192 type : "error" ,
186- message : formatRubyError ( e ) ,
193+ message : formatRubyError ( e , true ) ,
187194 } ) ;
188195 }
189196
0 commit comments