Skip to content
Browse files

added error logging using trycatch...exception handling to log errors…

… in job.log
  • Loading branch information...
1 parent 904cb87 commit c4eea42aefb2d727debf1770e7d91ae3ce10d3f6 @rdulepet committed
Showing with 18 additions and 2 deletions.
  1. +2 −2 instrument_developer_script.rb
  2. +16 −0 testing/testerror_instrumentation.r
View
4 instrument_developer_script.rb
@@ -45,7 +45,7 @@ def self.instrument_code orig_r_script
curr_caption = ""
# automatically take care of HEADER mandatory tag
- arr_instrumented[arr_instrumented.length] = "library(\"R2HTML\")\ncrdata_job_log <- file(\"job.log\", open=\"wt\")\nsink(crdata_job_log)\ncrdata_target <- HTMLInitFile(getwd(), filename=\"index\")\n"
+ arr_instrumented[arr_instrumented.length] = "library(\"R2HTML\")\ncrdata_job_log <- file(\"job.log\", open=\"wt\")\nsink(crdata_job_log)\ncrdata_target <- HTMLInitFile(getwd(), filename=\"index\")\ntryCatch({\n"
File.open(orig_r_script, "r").each do | line |
=begin
@@ -106,7 +106,7 @@ def self.instrument_code orig_r_script
end
# automatically take care of FOOTER mandatory tag
- arr_instrumented[arr_instrumented.length] = "\nHTMLEndFile()\nsink()\n"
+ arr_instrumented[arr_instrumented.length] = "\nHTMLEndFile()\nsink()\n\n}, interrupt = function(ex) {\nprint (\"got exception\");\nprint(ex);\n}, error = function(ex) {\nprint (\"got error\");\nprint(ex);\n}, finally = {\n})\n"
# now write instrumented array into the original R script
r_script_file_handle = File.open(orig_r_script, aModeString="w")
View
16 testing/testerror_instrumentation.r
@@ -0,0 +1,16 @@
+ # < crdata_title>This is brand new CRDATA run report</ crdata_title>
+tmp <- as.data.frame(matrix(rnorm(100),ncol=10))
+summary(tmp)
+#<crdata_object>tmp</crdata_object>
+#<crdata_section/>
+
+#<crdata_image caption="First Graph">
+plot(tmp)
+#</crdata_image>
+
+#<crdata_image caption="Second Graph">plot(tmp)
+#</crdata_image>
+print(zzz)
+#<crdata_image caption="Third Graph">plot(tmp)</crdata_image>
+
+#<crdata_image>plot(tmp)</crdata_image>

0 comments on commit c4eea42

Please sign in to comment.
Something went wrong with that request. Please try again.