From 5e18bf5d039207cc3ca6758d4293efea265e18ca Mon Sep 17 00:00:00 2001 From: bingwang-ms <66248323+bingwang-ms@users.noreply.github.com> Date: Wed, 23 Dec 2020 04:20:03 +0800 Subject: [PATCH] Fix exception handling in python3 (#1324) **- What I did** In python3, message is not an attribute of Exception. As a result, another exception will be thrown in exception handling code. ``` "Traceback (most recent call last):", " File \"/usr/local/bin/fdbshow\", line 154, in ", " main()", " File \"/usr/local/bin/fdbshow\", line 150, in main", " print(e.message)", "AttributeError: 'RuntimeError' object has no attribute 'message'" ``` This commit addressed the issue. **- How I did it** Relpace `e.message` with `str(e)`. Signed-off-by: bingwang --- scripts/aclshow | 2 +- scripts/ecnconfig | 2 +- scripts/fdbclear | 2 +- scripts/fdbshow | 2 +- scripts/lldpshow | 2 +- scripts/mmuconfig | 2 +- scripts/natclear | 2 +- scripts/natconfig | 2 +- scripts/natshow | 2 +- scripts/nbrshow | 2 +- scripts/portconfig | 2 +- scripts/sonic_sku_create.py | 4 ++-- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/aclshow b/scripts/aclshow index 36f73e4e3452..a9ee1692091f 100755 --- a/scripts/aclshow +++ b/scripts/aclshow @@ -212,7 +212,7 @@ def main(): acls.previous_counters() acls.display_acl_stat(args.all) except Exception as e: - print(e.message, file=sys.stderr) + print(str(e), file=sys.stderr) sys.exit(1) if __name__ == "__main__": diff --git a/scripts/ecnconfig b/scripts/ecnconfig index c0ac26b817ea..96061dc5d1d2 100755 --- a/scripts/ecnconfig +++ b/scripts/ecnconfig @@ -326,7 +326,7 @@ def main(): sys.exit(1) except Exception as e: - print("Exception caught: ", e.message, file=sys.stderr) + print("Exception caught: ", str(e), file=sys.stderr) sys.exit(1) if __name__ == "__main__": diff --git a/scripts/fdbclear b/scripts/fdbclear index b7eec2d555cb..ceb5f22b7e16 100644 --- a/scripts/fdbclear +++ b/scripts/fdbclear @@ -50,7 +50,7 @@ def main(): fdb.send_notification("ALL", "ALL") print("FDB entries are cleared.") except Exception as e: - print(e.message) + print(str(e)) sys.exit(1) if __name__ == "__main__": diff --git a/scripts/fdbshow b/scripts/fdbshow index 759472a56d29..169bf7cf3c0b 100755 --- a/scripts/fdbshow +++ b/scripts/fdbshow @@ -147,7 +147,7 @@ def main(): fdb = FdbShow() fdb.display(args.vlan, args.port) except Exception as e: - print(e.message) + print(str(e)) sys.exit(1) if __name__ == "__main__": diff --git a/scripts/lldpshow b/scripts/lldpshow index 1530a56f8b68..05ecb9c49e82 100755 --- a/scripts/lldpshow +++ b/scripts/lldpshow @@ -201,7 +201,7 @@ def main(): lldp.parse_info(lldp_detail_info) lldp.display_sum(lldp_detail_info) except Exception as e: - print(e.message, file=sys.stderr) + print(str(e), file=sys.stderr) sys.exit(1) diff --git a/scripts/mmuconfig b/scripts/mmuconfig index e44fcf0e4d6a..96f3af106406 100755 --- a/scripts/mmuconfig +++ b/scripts/mmuconfig @@ -151,7 +151,7 @@ def main(config): sys.exit(1) except Exception as e: - print("Exception caught:", e.message, file=sys.stderr) + print("Exception caught:", str(e), file=sys.stderr) sys.exit(1) if __name__ == "__main__": diff --git a/scripts/natclear b/scripts/natclear index 2a46aaab18e5..8137218ac569 100644 --- a/scripts/natclear +++ b/scripts/natclear @@ -63,7 +63,7 @@ def main(): nat.send_statistics_notification("STATISTICS", "ALL") print("\nNAT statistics are cleared.") except Exception as e: - print(e.message) + print(str(e)) sys.exit(1) if __name__ == "__main__": diff --git a/scripts/natconfig b/scripts/natconfig index 8254c37b2ef5..e4e88ad580c2 100644 --- a/scripts/natconfig +++ b/scripts/natconfig @@ -367,7 +367,7 @@ def main(): nat.fetch_nat_zone() nat.display_nat_zone() except Exception as e: - print(e.message) + print(str(e)) sys.exit(1) if __name__ == "__main__": diff --git a/scripts/natshow b/scripts/natshow index cd0a58c38b8c..70a517070379 100644 --- a/scripts/natshow +++ b/scripts/natshow @@ -404,7 +404,7 @@ def main(): nat.display_count() except Exception as e: - print(e.message) + print(str(e)) sys.exit(1) if __name__ == "__main__": diff --git a/scripts/nbrshow b/scripts/nbrshow index dddeaa696a9a..694e64242d42 100644 --- a/scripts/nbrshow +++ b/scripts/nbrshow @@ -261,7 +261,7 @@ def main(): arp.display() except Exception as e: - print(e.message) + print(str(e)) sys.exit(1) diff --git a/scripts/portconfig b/scripts/portconfig index cbb5cea938e8..c850cbe2fe20 100755 --- a/scripts/portconfig +++ b/scripts/portconfig @@ -99,7 +99,7 @@ def main(): sys.exit(1) except Exception as e: - print(e.message, file=sys.stderr) + print(str(e), file=sys.stderr) sys.exit(1) if __name__ == "__main__": diff --git a/scripts/sonic_sku_create.py b/scripts/sonic_sku_create.py index 8ba9b3e520dd..846f45482548 100755 --- a/scripts/sonic_sku_create.py +++ b/scripts/sonic_sku_create.py @@ -631,7 +631,7 @@ def create_sku_dir(self): try: shutil.copytree(self.base_sku_dir, self.new_sku_dir) except OSError as e: - print(e.message, file=sys.stderr) + print(str(e), file=sys.stderr) def remove_sku_dir(self): # remove SKU directory @@ -653,7 +653,7 @@ def remove_sku_dir(self): else: print("SKU directory: "+ self.new_sku_dir + " was NOT removed") except OSError as e: - print(e.message, file=sys.stderr) + print(str(e), file=sys.stderr) def platform_specific(self): # Function that checks for Platform specific restrictions