Skip to content

Commit

Permalink
#170 Update parser error handler to always output something. Template…
Browse files Browse the repository at this point in the history
… the tlm_extractor config files. Use ERB in Table Manager config.
  • Loading branch information
jmthomas committed Jul 17, 2015
1 parent 28e830c commit 936dfd4
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 244 deletions.
223 changes: 3 additions & 220 deletions demo/config/tools/table_manager/TLMMonitoringTable_def.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions demo/config/tools/tlm_extractor/_adcs_time.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ITEM INST ADCS TIMESECONDS
ITEM INST ADCS TIMEFORMATTED
2 changes: 1 addition & 1 deletion demo/config/tools/tlm_extractor/tlm_extractor.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ITEM INST ADCS TIMEFORMATTED
<%= render "_adcs_time.txt" %>
ITEM INST ADCS Q1 RAW
ITEM INST ADCS Q1
ITEM INST ADCS Q1 FORMATTED
Expand Down
2 changes: 1 addition & 1 deletion demo/config/tools/tlm_extractor/tlm_extractor2.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ITEM INST ADCS TIMEFORMATTED
<%= render "_adcs_time.txt" %>
ITEM INST ADCS Q2 RAW
2 changes: 1 addition & 1 deletion demo/config/tools/tlm_extractor/tlm_extractor3.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ITEM INST ADCS TIMEFORMATTED
<%= render "_adcs_time.txt" %>
ITEM INST ADCS Q3 RAW
2 changes: 1 addition & 1 deletion demo/config/tools/tlm_extractor/tlm_extractor4.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ITEM INST ADCS TIMEFORMATTED
<%= render "_adcs_time.txt" %>
ITEM INST ADCS Q4 RAW
50 changes: 30 additions & 20 deletions lib/cosmos/config/config_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,27 +192,12 @@ def parse_file(filename,
PARSING_REGEX,
&block)
rescue Exception => e
# If we had an error parsing write out the parsed results for debugging
default_tmp_folder = File.join(Cosmos::USERPATH, 'outputs', 'tmp')
if File.exist?(default_tmp_folder)
begin
File.open(File.join(default_tmp_folder, "parser_error_#{File.basename(filename)}"), 'w') do |save_file|
save_file.puts e.formatted
save_file.puts "\nParsed Data (will only be present if parse ran successfully):"
save_file.puts
if defined? file
file.rewind
save_file.puts file.read
end
save_file.puts "\nUnparsed Data:"
save_file.puts
save_file.puts unparsed_data if defined? unparsed_data
end
rescue
# Oh well - we tried
end
debug_file = create_debug_output_file(filename, file, unparsed_data, e)
if debug_file
raise e, "#{e}\nDebug output in #{debug_file}", e.backtrace
else
raise e
end
raise e
ensure
file.close unless file.closed?
end
Expand Down Expand Up @@ -349,6 +334,31 @@ def self.handle_defined_constants(value)

protected

# Writes the parsed results for debugging if we had an error parsing
def create_debug_output_file(filename, file, unparsed_data, exception)
tmp_folder = File.join(Cosmos::USERPATH, 'outputs', 'tmp')
tmp_folder = Cosmos::USERPATH unless File.exist?(tmp_folder)
debug_file = File.join(tmp_folder, "parser_error_#{File.basename(filename)}")
begin
File.open(debug_file, 'w') do |save_file|
save_file.puts exception.formatted
save_file.puts "\nParsed Data (will only be present if parse ran successfully):"
save_file.puts
if defined? file
file.rewind
save_file.puts file.read
end
save_file.puts "\nUnparsed Data:"
save_file.puts
save_file.puts unparsed_data if defined? unparsed_data
end
rescue
# Oh well - we tried
debug_file = nil
end
debug_file
end

# Iterates over each line of the io object and yields the keyword and
# parameters
#~ def parse_loop(
Expand Down

0 comments on commit 936dfd4

Please sign in to comment.