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

pydevd_process_net_command.py this file frequently wrong as UnicodeDecodeError #183

Open
fangplu opened this issue Feb 26, 2024 · 0 comments

Comments

@fangplu
Copy link

fangplu commented Feb 26, 2024

def _on_run(self):
read_buffer = ""
try:

        while not self.killReceived:
            try:
                r = self.sock.recv(1024)
            except:
                if not self.killReceived:
                    traceback.print_exc()
                    self.handle_except()
                return #Finished communication.

            #Note: the java backend is always expected to pass utf-8 encoded strings. We now work with unicode
            #internally and thus, we may need to convert to the actual encoding where needed (i.e.: filenames
            #on python 2 may need to be converted to the filesystem encoding).
            if hasattr(r, 'decode'):

                r = r.decode('utf-8')

            read_buffer += r
            if DebugInfoHolder.DEBUG_RECORD_SOCKET_READS:
                sys.stderr.write(u'debugger: received >>%s<<\n' % (read_buffer,))
                sys.stderr.flush()

            if len(read_buffer) == 0:
                self.handle_except()
                break
            while read_buffer.find(u'\n') != -1:
                command, read_buffer = read_buffer.split(u'\n', 1)

                args = command.split(u'\t', 2)
                try:
                    cmd_id = int(args[0])
                    pydev_log.debug('Received command: %s %s\n' % (ID_TO_MEANING.get(str(cmd_id), '???'), command,))
                    self.process_command(cmd_id, int(args[1]), args[2])
                except:
                    traceback.print_exc()
                    sys.stderr.write("Can't process net command: %s\n" % command)
                    sys.stderr.flush()

    except:
        traceback.print_exc()
        self.handle_except()

When starting debugging frequently wrong show :
r = r.decode('utf-8')
^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 1022-1023: unexpected end of data

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

1 participant