[ONOS-7260]: Adding error/exception handling to the R Scripts.
Change-Id: Id12e1effb9041079b57242ae35a64caaa47ef19b
diff --git a/TestON/JenkinsFile/scripts/SCPFmastershipFailoverLat.R b/TestON/JenkinsFile/scripts/SCPFmastershipFailoverLat.R
index 8681f29..30f7bca 100644
--- a/TestON/JenkinsFile/scripts/SCPFmastershipFailoverLat.R
+++ b/TestON/JenkinsFile/scripts/SCPFmastershipFailoverLat.R
@@ -64,7 +64,7 @@
"<directory-to-save-graphs>",
sep=" " ) )
- q() # basically exit(), but in R
+ quit( status = 1 ) # basically exit(), but in R
}
# -----------------
@@ -134,8 +134,20 @@
print( "Combining averages into a list." )
-avgs <- c( fileData[ 'kill_deact_avg' ],
- fileData[ 'deact_role_avg' ] )
+requiredColumns <- c( "kill_deact_avg", "deact_role_avg" )
+
+tryCatch( avgs <- c( fileData[ requiredColumns] ),
+ error = function( e ) {
+ print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." )
+ print( "Required columns: " )
+ print( requiredColumns )
+ print( "Actual columns: " )
+ print( names( fileData ) )
+ print( "Error dump:" )
+ print( e )
+ quit( status = 1 )
+ }
+ )
# --------------------
# Construct Data Frame
@@ -193,7 +205,7 @@
legend.key.size = unit( 1.5, 'lines' ) )
barColors <- scale_fill_manual( values=c( "#F77670",
- "#619DFA" ) )
+ "#619DFA" ) )
wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
@@ -264,10 +276,16 @@
print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
-ggsave( errBarOutputFile,
- width = imageWidth,
- height = imageHeight,
- dpi = imageDPI )
+tryCatch( ggsave( errBarOutputFile,
+ width = imageWidth,
+ height = imageHeight,
+ dpi = imageDPI ),
+ error = function( e ){
+ print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
+ print( e )
+ quit( status = 1 )
+ }
+ )
print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) )
@@ -317,9 +335,16 @@
print( paste( "Saving stacked bar chart to", stackedBarOutputFile ) )
-ggsave( stackedBarOutputFile,
- width = imageWidth,
- height = imageHeight,
- dpi = imageDPI )
+tryCatch( ggsave( stackedBarOutputFile,
+ width = imageWidth,
+ height = imageHeight,
+ dpi = imageDPI ),
+ error = function( e ){
+ print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
+ print( e )
+ quit( status = 1 )
+ }
+ )
print( paste( "[SUCCESS] Successfully wrote stacked bar chart out to", stackedBarOutputFile ) )
+quit( status = 0 )