Skip to content

Commit

Permalink
Fix exception handling in python3 (#1324)
Browse files Browse the repository at this point in the history
**- 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 <module>", 
        "    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 <[email protected]>
  • Loading branch information
bingwang-ms authored Dec 22, 2020
1 parent b6221f4 commit 5e18bf5
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion scripts/aclshow
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/ecnconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/fdbclear
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/fdbshow
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/lldpshow
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion scripts/mmuconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/natclear
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/natconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/natshow
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/nbrshow
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def main():
arp.display()

except Exception as e:
print(e.message)
print(str(e))
sys.exit(1)


Expand Down
2 changes: 1 addition & 1 deletion scripts/portconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
4 changes: 2 additions & 2 deletions scripts/sonic_sku_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5e18bf5

Please sign in to comment.