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

'OSError [Errno5] Input/output error' occurred while invoking logger #2784

Closed
CharmingYang0 opened this issue Mar 2, 2018 · 8 comments
Closed

Comments

@CharmingYang0
Copy link

I designed a robot framework testing library, a specific method defined as below:

import json
from robot.api import logger
@staticmethod
def select_list_first_element_info(select_list, select_key):
    if select_list and isinstance(select_list, list) and select_key:
        data_dict = select_list[0]
        json_dict = json.loads(data_dict)
        if select_key in json_dict.keys():
            return json_dict.get(select_key)
        else:
            logger.error(r"%s cannot be found in keys of dict variable json_dict." % select_key, html=True)
            return ""
    else:
        logger.error(r"select_list is not valid list or select_key is null.", html=True)
        return ""

But, I/O error occurred regardless of html=True or not.

20180302 01:18:55.723 - INFO - +--- START KW: lhvapi.Select List First Element Info [ ${dc_list} | ${key_dcid} ]
20180302 01:18:55.724 - ERROR - select_list is not valid list or select_key is null.
20180302 01:18:55.727 - FAIL - OSError: [Errno 5] Input/output error
20180302 01:18:55.727 - DEBUG - Traceback (most recent call last):
File "/home/autorunner/virtual_env/lib/python3.6/site-packages/lhvapi/LhvRequests.py", line 162, in select_list_first_element_info
logger.error(r"select_list is not valid list or select_key is null.", html=True)
File "/home/autorunner/virtual_env/lib/python3.6/site-packages/robot/api/logger.py", line 131, in error
write(msg, 'ERROR', html)
File "/home/autorunner/virtual_env/lib/python3.6/site-packages/robot/api/logger.py", line 88, in write
librarylogger.write(msg, level, html)
File "/home/autorunner/virtual_env/lib/python3.6/site-packages/robot/output/librarylogger.py", line 44, in write
LOGGER.log_message(Message(msg, level, html))
File "/home/autorunner/virtual_env/lib/python3.6/site-packages/robot/output/logger.py", line 154, in _log_message
self.message(msg)
File "/home/autorunner/virtual_env/lib/python3.6/site-packages/robot/output/logger.py", line 141, in message
logger.message(msg)
File "/home/autorunner/virtual_env/lib/python3.6/site-packages/robot/output/console/quiet.py", line 28, in message
self._stderr.error(msg.message, msg.level)
File "/home/autorunner/virtual_env/lib/python3.6/site-packages/robot/output/console/highlighting.py", line 74, in error
self.write(' ] %s\n' % message)
File "/home/autorunner/virtual_env/lib/python3.6/site-packages/robot/output/console/highlighting.py", line 51, in write
self.stream.write(console_encode(text, stream=self.stream))

OS: CentOS Linux release 7.4.1708 (Core)
Python: v3.6.3
Robot Framework: v3.0.2

It confused me for while, right now I have to remove logger codes.

@CharmingYang0
Copy link
Author

Open the same issue in stackoverflow .

@pekkaklarck
Copy link
Member

The error occurs when Robot tries to write into the stderr. Have you redirected it or otherwise somehow configured it somehow? Do you run tests directly on the command line or otherwise?

@CharmingYang0
Copy link
Author

@pekkaklarck
Robot was invoked in python code instead of command line, see below.

from robot import rebot_cli, run as robot_run
...
result = robot_run(test_suite, 
                        variable=self.rf_variables, 
                        listener=self.rf_listener, 
                        include=self.rf_include, 
                        quiet=True)
...

@pekkaklarck
Copy link
Member

You didn't answer the question about stderr. Do you get same error if you run tests normally with the robot command?

@CharmingYang0
Copy link
Author

@pekkaklarck
With updated method like below, robot can logging error normally in command line.

    @staticmethod
    def select_list_first_element_info(select_list, select_key):
        if select_list and isinstance(select_list, list) and select_key:
            data_dict = select_list[0]
            json_dict = json.dumps(data_dict)
            json_dict = json.loads(json_dict)
            if select_key in json_dict.keys():
                logger.error("ABCD EF")
                return json_dict.get(select_key)
            else:
                return ""
        else:
            return ""

image

@CharmingYang0
Copy link
Author

@pekkaklarck
Need to mention that, the system that invokes robot_run consists of flask, celery&redis.

@pekkaklarck
Copy link
Member

I don't see any real difference between the two examples. Can you provide a simple example that demonstrates the problem? Also, please answer the questions I asked earlier.

@CharmingYang0
Copy link
Author

@pekkaklarck
You are right, stderr is redirected by other modules while robot logging to it.
Thanks for your hint.

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

No branches or pull requests

2 participants