Skip to content

Conversation

@namsonx
Copy link
Collaborator

@namsonx namsonx commented Apr 11, 2024

No description provided.

Copy link
Collaborator

@HolQue HolQue left a comment

Choose a reason for hiding this comment

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

Hi Son,

the performance issues are solved. Your code looks good. But I cannot find the new output
failedJsonDoc (lines starting with "Nearby: "). I am confused.

Have you tested the output?

                if failedJsonDoc is None:
                    print(f"================================= is None")
                    jsonException = f"{error}\nIn file: '{jFile}'"
                else:
                    print(f"================================= is not None")
                    jsonException = f"{error}\nNearby: '{failedJsonDoc}'\nIn file: '{jFile}'"

is None always

            if failedJsonDoc is None:
                print(f"================================= is None (2)")
                jsonException = f"${error}\nIn file: '{jFile}'"
            else:
                print(f"================================= is None (2)")
                jsonException = f"${error}\nNearby: '{failedJsonDoc}'\nIn file: '{jFile}'"

Still ${error} ;-)

Is always not a JSON exception object. Means: .doc is not an element of jsonDecodeError. I have no idea why.

    def __getFailedJsonDoc(jsonDecodeError=None, areaBeforePosition=50, areaAfterPosition=20, oneLine=True):
        failedJsonDoc = None
        if jsonDecodeError is None:
            return failedJsonDoc
        try:
            jsonDoc = jsonDecodeError.doc
        except:
            # 'jsonDecodeError' seems not to be a JSON exception object ('doc' not available)
            print(f"================================= NOT a JSON exception object")
            return failedJsonDoc

No such problems when accessing .doc immediately:

            except Exception as error:
                self.__reset()

                intermediateDocOutput = error.doc
                print(f"================================= intermediateDocOutput (1): {intermediateDocOutput}")

                failedJsonDoc = self.__getFailedJsonDoc(error)
                jsonException = "not defined"
                if failedJsonDoc is None:
                    print(f"================================= is None")
                    jsonException = f"{error}\nIn file: '{jFile}'"
                else:
                    print(f"================================= is not None")
                    jsonException = f"{error}\nNearby: '{failedJsonDoc}'\nIn file: '{jFile}'"
                raise Exception(jsonException)

Assumption: Something went wrong when passing the error to:

failedJsonDoc = self.__getFailedJsonDoc(error)

Still no idea why.

Trying to summarize:

Within an except block we have an exception object available. If we pass this exception object to a method of the same class, we get lost of this object. This in new to me.

We need access to two informations:

jsonDecodeError.doc
jsonDecodeError.pos

Therefore, instead of:

def __getFailedJsonDoc(jsonDecodeError=None, areaBeforePosition=50, areaAfterPosition=20, oneLine=True):

an alternative implementation could be:

jsonDecodeErrorPos = jsonDecodeError.pos
jsonDecodeErrorDoc = jsonDecodeError.doc
def __getFailedJsonDoc(jsonDecodeErrorPos=None, jsonDecodeErrorDoc=None, areaBeforePosition=50, areaAfterPosition=20, oneLine=True):

I print what I put inside __getFailedJsonDoc:

            except Exception as error:
                self.__reset()

                print(f"================================= (1) error.pos: {error.pos}")
                print(f"================================= (1) error.doc: {error.doc}")

                failedJsonDoc = self.__getFailedJsonDoc(error.pos, error.doc)

And I print what I get inside the method:

    def __getFailedJsonDoc(jsonDecodeErrorPos=None, jsonDecodeErrorDoc=None, areaBeforePosition=50, areaAfterPosition=20, oneLine=True):
        failedJsonDoc = None
        if ( (jsonDecodeErrorPos is None) or (jsonDecodeErrorDoc is None) ):
            return failedJsonDoc
        print(f"================================= (__getFailedJsonDoc) jsonDecodeErrorPos: {jsonDecodeErrorPos}")
        print(f"================================= (__getFailedJsonDoc) jsonDecodeErrorDoc: {jsonDecodeErrorDoc}")

Result:

================================= (1) error.pos: 15
================================= (1) error.doc: {
"param1" : 1
"param2" : 2
}

================================= (__getFailedJsonDoc) jsonDecodeErrorPos: <JsonPreprocessor.CJsonPreprocessor.CJsonPreprocessor object at 0x000001BEA02394C0>
================================= (__getFailedJsonDoc) jsonDecodeErrorDoc: 15

I am lost now :-(

@namsonx
Copy link
Collaborator Author

namsonx commented Apr 11, 2024

Hi Son,

the performance issues are solved. Your code looks good. But I cannot find the new output failedJsonDoc (lines starting with "Nearby: "). I am confused.

Have you tested the output?

                if failedJsonDoc is None:
                    print(f"================================= is None")
                    jsonException = f"{error}\nIn file: '{jFile}'"
                else:
                    print(f"================================= is not None")
                    jsonException = f"{error}\nNearby: '{failedJsonDoc}'\nIn file: '{jFile}'"

is None always

            if failedJsonDoc is None:
                print(f"================================= is None (2)")
                jsonException = f"${error}\nIn file: '{jFile}'"
            else:
                print(f"================================= is None (2)")
                jsonException = f"${error}\nNearby: '{failedJsonDoc}'\nIn file: '{jFile}'"

Still ${error} ;-)

Is always not a JSON exception object. Means: .doc is not an element of jsonDecodeError. I have no idea why.

    def __getFailedJsonDoc(jsonDecodeError=None, areaBeforePosition=50, areaAfterPosition=20, oneLine=True):
        failedJsonDoc = None
        if jsonDecodeError is None:
            return failedJsonDoc
        try:
            jsonDoc = jsonDecodeError.doc
        except:
            # 'jsonDecodeError' seems not to be a JSON exception object ('doc' not available)
            print(f"================================= NOT a JSON exception object")
            return failedJsonDoc

No such problems when accessing .doc immediately:

            except Exception as error:
                self.__reset()

                intermediateDocOutput = error.doc
                print(f"================================= intermediateDocOutput (1): {intermediateDocOutput}")

                failedJsonDoc = self.__getFailedJsonDoc(error)
                jsonException = "not defined"
                if failedJsonDoc is None:
                    print(f"================================= is None")
                    jsonException = f"{error}\nIn file: '{jFile}'"
                else:
                    print(f"================================= is not None")
                    jsonException = f"{error}\nNearby: '{failedJsonDoc}'\nIn file: '{jFile}'"
                raise Exception(jsonException)

Assumption: Something went wrong when passing the error to:

failedJsonDoc = self.__getFailedJsonDoc(error)

Still no idea why.

Trying to summarize:

Within an except block we have an exception object available. If we pass this exception object to a method of the same class, we get lost of this object. This in new to me.

We need access to two informations:

jsonDecodeError.doc
jsonDecodeError.pos

Therefore, instead of:

def __getFailedJsonDoc(jsonDecodeError=None, areaBeforePosition=50, areaAfterPosition=20, oneLine=True):

an alternative implementation could be:

jsonDecodeErrorPos = jsonDecodeError.pos
jsonDecodeErrorDoc = jsonDecodeError.doc
def __getFailedJsonDoc(jsonDecodeErrorPos=None, jsonDecodeErrorDoc=None, areaBeforePosition=50, areaAfterPosition=20, oneLine=True):

Hello Holger,

I tried to move the function getFailedJsonDoc out of the CJsonPreprocessor class, then the "Nearby: ..." log appears.
So, I think the alternative solution is move this function out of the CJsonPreprocessor class as your first implementation.

Thank you,
Son

@HolQue
Copy link
Collaborator

HolQue commented Apr 11, 2024

Hi Son,

yes, I agree.

@HolQue
Copy link
Collaborator

HolQue commented Apr 11, 2024

Hi Son,

the self is missing:

def __getFailedJsonDoc(jsonDecodeError=None, areaBeforePosition=50, areaAfterPosition=20, oneLine=True):

Should be

def __getFailedJsonDoc(self, jsonDecodeError=None, areaBeforePosition=50, areaAfterPosition=20, oneLine=True):

o.m.g.

@HolQue
Copy link
Collaborator

HolQue commented Apr 11, 2024

Success!

The "Nearby" is back :-)

@test-fullautomation test-fullautomation added enhancement New feature or request 0.11.0 labels Apr 11, 2024
@test-fullautomation test-fullautomation added this to the 0.11.0 milestone Apr 11, 2024
Copy link
Owner

@test-fullautomation test-fullautomation left a comment

Choose a reason for hiding this comment

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

Hi Son,
looks good to me!
Thank you,
Thomas

@test-fullautomation test-fullautomation merged commit 3b7bbea into develop Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.11.0 enhancement New feature or request

Projects

Development

Successfully merging this pull request may close these issues.

4 participants