Skip to content

stdio_client init with errlog #645

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

Open
vincent-pli opened this issue May 7, 2025 · 2 comments
Open

stdio_client init with errlog #645

vincent-pli opened this issue May 7, 2025 · 2 comments

Comments

@vincent-pli
Copy link

How to capture the stderr from server, I saw there is a params named: errlog, its default value is sys.stderr, that caused any stderr from server side will be print in the console/terminal

I do not like the behavior, at least I want capture the error log from server and print with prefix(maybe "error-received: {original-err}")

but I cannot figure out how to use errlog param, I write a file-like object, something like this:

class ErrorPrefixTextIO(io.TextIOBase):
    def __init__(self, original_stream=None):
        self.original_stream = original_stream or sys.stderr
    
    def write(self, message: str) -> int:
        if message.strip():
            self.original_stream.write(f"error- {message}")
            self.original_stream.flush()
        return len(message)
    
    def flush(self) -> None:
        self.original_stream.flush()

    def fileno(self) -> int:
        return self.original_stream.fileno()

    def close(self) -> None:
        if hasattr(self.original_stream, 'close'):
            self.original_stream.close()

it's not work, seems the function write is ignored at all
besides that, I also try to assign a file object to errlog, it could work, the file is write with error from server, but I cannot add any prefix to original err message. any help, thanks

@zhangch-ss
Copy link

+1 I have a similar question, I want to capture errors from initializing the session, but I don't know how

@vincent-pli
Copy link
Author

I think the best way is to yield stderr besides stdin and stdout

yield read_stream, write_stream

then make errlog = subprocess.PIPE when call stdio_client

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