Catch Load Errors
-
What is the best way to catch and log extension load errors? I would like for SketchUp to log errors to a file, maybe print a note in the Ruby Console, but not interrupt loading with the Load Errors dialog.
I know I can redefine the load method, but I want to make sure I don't break something else.
-
This is for my own use - not for any that will be shared.
-
Jim,
Interesting question! What you request sounds like the switch many compilers provide to continue processing beyond the first error (with the addition that the error messages need to be captured somewhere accessible). Just as with a compiler, this would risk causing a cascade of nonsense errors from subsequent loaded files, but also just as with a compiler that might be a tradeoff the developer was willing to make.
-
Something like ?
Assuming we are loading a folder of scripts - 'some_folder_path'...msg = "" Dir.entries(some_folder_path).grep(/.rb$/).each{|rb| dest = File.join(some_folder_path, rb) begin load(dest) rescue Exception => err msg << "#{some_folder_path}/#{rb} >>> #{err}\n" end } file = File.open(path_to_report. "w") file.puts(msg) file.close
In rare cases when there's a "load error" it is written into the 'path_to_report' file ?
-
One thing to beware of is that Sketchup::require/load annoyingly doesn't raise ruby errors - but instead just output the error text. So you might want to hook into $stdout and $strerr to catch that as well. (This is something I suggest only because you mention it was for a personal tool.)
Advertisement