Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add try/except blocks around external text file read operations to catch encoding-related exceptions #31

Merged
merged 7 commits into from
Jun 23, 2022

Conversation

mosherubin
Copy link
Collaborator

@mosherubin mosherubin commented Jun 20, 2022

Added try/except blocks around read operations of external files. These are meant to catch any Unicode-related exceptions thrown while reading these files (e.g., the file contains an invalid UTF-8 sequence), providing more robust code. The except clauses will log a message pointing to the file that causes the exception. External files include:

  • C++ source file being processed
  • The filefilter.txt file
  • Rule Python script files

These modifications were made because NsiqCppStyle often failed to read external files, due to encoding issues in the source files (e.g., invalid UTF-8 sequences, incorrect UTF16 encoding). I was often left puzzling over which file had the invalid sequence. With the try/except blocks, the user is told which file is problematic.

(1) Modifying Python 2 functions and code style not compatible with Python 3, including adding parentheses to all "print" invocations
(2) Updating the version string from "0.2.2.13" to "0.3.0.1"
(3) Minor grammatical corrections
(4) Changing "except Usage" to "except Exception" (solved a thrown exception when Usage() function invoked internally)
(2) Modified all file(...) calls to open(...)
(3) Modified calls to deprecated CmpObjects(...) comparison function (not supported in Python 3) to call a new function CmpObjects() in nsiqcppstyle_util.py
(4) Removed redundant "import" statements in all engine script files
(5) Moved all duplicate functions to nsiqcppstyle_util.py, all source files now call these functions
(6) Removed all explicit Python 2.x code
…se are meant to catch any Unicode-related exceptions thrown while reading these files (e.g., the file contains an invalid UTF-8 sequence), providing more robust code. The except clauses will log a message pointing to the file that causes the exception. External files include:

(*) C++ source file being processed
(*) The filefilter.txt file
(*) Rule Python script files
…nto kunaltyagi-master

# Conflicts:
#	nsiqcppstyle_exe.py
@kunaltyagi
Copy link
Owner

I think you've not pushed the latest changes

@mosherubin
Copy link
Collaborator Author

Got it - as part of the mixup, I needed to merge my repo's pull request-created branch into its master branch. Now you can see the changes.

Copy link
Owner

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comment, rest lgtm

@kunaltyagi kunaltyagi merged commit 05105d9 into kunaltyagi:master Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants