Skip to content

Commit

Permalink
return an error status on error in rosbag (#1257)
Browse files Browse the repository at this point in the history
I added some sys.exit(1)'s to rosbag commands to help with scripting.
Specifically, I expected a call to `rosbag info test.bag.active` to
return an error when the bag needed re-indexing.
  • Loading branch information
phil-marble authored and dirk-thomas committed Dec 13, 2017
1 parent 480d0c4 commit 44b33aa
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tools/rosbag/src/rosbag/rosbag_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,13 @@ def info_cmd(argv):
except ROSBagUnindexedException as ex:
print('ERROR bag unindexed: %s. Run rosbag reindex.' % arg,
file=sys.stderr)
sys.exit(1)
except ROSBagException as ex:
print('ERROR reading %s: %s' % (arg, str(ex)), file=sys.stderr)
sys.exit(1)
except IOError as ex:
print('ERROR reading %s: %s' % (arg, str(ex)), file=sys.stderr)
sys.exit(1)


def handle_topics(option, opt_str, value, parser):
Expand Down Expand Up @@ -334,7 +337,7 @@ def eval_fn(topic, m, t):
inbag = Bag(inbag_filename)
except ROSBagUnindexedException as ex:
print('ERROR bag unindexed: %s. Run rosbag reindex.' % inbag_filename, file=sys.stderr)
return
sys.exit(1)

try:
meter = ProgressMeter(outbag_filename, inbag._uncompressed_size)
Expand Down Expand Up @@ -432,7 +435,7 @@ def fix_cmd(argv):
except ROSBagUnindexedException as ex:
print('ERROR bag unindexed: %s. Run rosbag reindex.' % inbag_filename,
file=sys.stderr)
return
sys.exit(1)

if len(migrations) == 0:
os.rename(outname, outbag_filename)
Expand All @@ -449,6 +452,7 @@ def fix_cmd(argv):

print('Try running \'rosbag check\' to create the necessary rule files or run \'rosbag fix\' with the \'--force\' option.')
os.remove(outname)
sys.exit(1)

def check_cmd(argv):
parser = optparse.OptionParser(usage='rosbag check BAG [-g RULEFILE] [EXTRARULES1 EXTRARULES2 ...]', description='Determine whether a bag is playable in the current system, or if it can be migrated.')
Expand Down Expand Up @@ -478,7 +482,7 @@ def check_cmd(argv):
Bag(args[0])
except ROSBagUnindexedException as ex:
print('ERROR bag unindexed: %s. Run rosbag reindex.' % args[0], file=sys.stderr)
return
sys.exit(1)

mm = MessageMigrator(args[1:] + append_rule, not options.noplugins)

Expand Down

0 comments on commit 44b33aa

Please sign in to comment.