Skip to content

Commit

Permalink
Fix wrong error handling in migration. (#1639)
Browse files Browse the repository at this point in the history
* Fix wrong error handling in migration.

self.(old|new)_types is supposed to be a dictionary, not a list

* Address PR 1639 comments.

* remove duplicate warning message
  • Loading branch information
omangin authored and dirk-thomas committed Aug 3, 2020
1 parent f9cc01b commit 60af411
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tools/rosbag/src/rosbag/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import os
import string
import sys
import traceback

import genmsg.msgs
import genpy
Expand Down Expand Up @@ -257,6 +258,9 @@ class MessageUpdateRule(object):

valid = False

class EmptyType(Exception):
pass

## Initialize class
def __init__(self, migrator, location):
# Every rule needs to hang onto the migrator so we can potentially use it
Expand All @@ -271,23 +275,26 @@ def __init__(self, migrator, location):
# Instantiate types dynamically based on definition
try:
if self.old_type == "":
raise Exception
raise self.EmptyType
self.old_types = genpy.dynamic.generate_dynamic(self.old_type, self.old_full_text)
self.old_class = self.old_types[self.old_type]
self.old_md5sum = self.old_class._md5sum
except:
self.old_types = []
except Exception as e:
if not isinstance(e, self.EmptyType):
traceback.print_exc(file=sys.stderr)
self.old_types = {}
self.old_class = None
self.old_md5sum = ""

try:
if self.new_type == "":
raise Exception
raise self.EmptyType
self.new_types = genpy.dynamic.generate_dynamic(self.new_type, self.new_full_text)
self.new_class = self.new_types[self.new_type]
self.new_md5sum = self.new_class._md5sum
except:
self.new_types = []
except Exception as e:
if not isinstance(e, self.EmptyType):
traceback.print_exc(file=sys.stderr)
self.new_types = {}
self.new_class = None
self.new_md5sum = ""

Expand Down

0 comments on commit 60af411

Please sign in to comment.