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

If the json file is incorrect formatted, show the impacted file #1665

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions libcodechecker/server/instance_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import psutil
import socket
import stat
from libcodechecker.logger import get_logger

LOG = get_logger('server')


def __getInstanceDescriptorPath(folder=None):
Expand Down Expand Up @@ -70,10 +73,14 @@ def __rewriteInstanceFile(append, remove, folder=None):
#
# Also, we remove the records to the given PIDs, if any exists.
append_pids = [i['pid'] for i in append]
instances = [i for i in json.load(f)
if i['pid'] not in append_pids and
(i['hostname'] + ":" + str(i['pid'])) not in remove and
__checkInstance(i['hostname'], i['pid'])]
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a function in our util to handle invalid json files:

def load_json_or_empty(path, default=None, kind=None):

It would be better to use this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sylvestre Do you plan to update this pull request? If yes please fix pycodestyle error:

libcodechecker/server/instance_manager.py:79:80: E501 line too long (80 > 79 characters)

Note: I have created a separate pull request (#1695) to handle invalid json files properly in all places. So if you fix the style error we will accept this pull request.

instances = [i for i in json.load(f)
if i['pid'] not in append_pids and
(i['hostname'] + ":" + str(i['pid'])) not in remove and
__checkInstance(i['hostname'], i['pid'])]
except ValueError:
LOG.error("Failed to load json file:")
LOG.error(f)

instances = instances + append

Expand Down