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

retry to enter raw repl #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

retry to enter raw repl #40

wants to merge 2 commits into from

Conversation

gschaden
Copy link

I had a problem, while listing the fs in mu-editor. They asked me to send the change request to the upstream module.
retry to enter raw repl when listing fs

microfs.py Outdated
serial.write(b"\r\x01")
flush_to_msg(serial, raw_repl_msg)
break
except:
Copy link
Owner

Choose a reason for hiding this comment

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

How about?

except Exception as ex:
    if i == 2:
        raise ex

Thus ensuring the exception is raised, even after the three attempts.

@carlosperate
Copy link
Contributor

carlosperate commented Jan 11, 2023

Do you also have the info about the exception raised when it fails? It would be really useful to understand what the root of the problem is.
Specially if it prints something to the console before the exception, as we'd be able to see what was the serial data:

microfs/microfs.py

Lines 68 to 72 in 3c28361

data = serial.read_until(msg)
if not data.endswith(msg):
if COMMAND_LINE_FLAG:
print(data)
raise IOError("Could not enter raw REPL.")

@gschaden
Copy link
Author

I added some logging to the flush_to_msg function


2023-01-13 00:35:54,016 - root:70(flush_to_msg) WARNING: data: b'hello\r\nMicroPython v1.18 on 2022-01-17; 4MB/OTA module with ESP32\r\nType "help()" for more information.\r\n>>> ', b'raw REPL; CTRL-B to exit\r\n>'
2023-01-13 00:35:54,016 - root:98(raw_on) WARNING: retry: 0, Could not enter raw REPL. (b'hello\r\nMicroPython v1.18 on 2022-01-17; 4MB/OTA module with ESP32\r\nType "help()" for more information.\r\n>>> ',b'raw REPL; CTRL-B to exit\r\n>')
2023-01-13 00:35:54,021 - root:70(flush_to_msg) WARNING: data: b'\r\n>>> \r\nraw REPL; CTRL-B to exit\r\n>', b'raw REPL; CTRL-B to exit\r\n>'
2023-01-13 00:35:54,032 - root:70(flush_to_msg) WARNING: data: b'OK\r\nMPY: soft reboot\r\n', b'soft reboot\r\n'

I don't know, if it is some timing issue

@carlosperate
Copy link
Contributor

carlosperate commented Jan 13, 2023

Thanks @gschaden, that is really useful!

It's a bit odd though, the microFS code is meant to read serial data until it receives b'raw REPL; CTRL-B to exit\r\n>'
And the logging you've posted clearly shows that message being received.

Is the string in this line of the log:

2023-01-13 00:35:54,016 - root:98(raw_on) WARNING: retry: 0, Could not enter raw REPL. (b'hello\r\nMicroPython v1.18 on 2022-01-17; 4MB/OTA module with ESP32\r\nType "help()" for more information.\r\n>>> ',b'raw REPL; CTRL-B to exit\r\n>')

Generated by this line of code?

raise IOError("Could not enter raw REPL. %s" % data)

I think it must be, as it's the only line of code in microFS using the Could not enter raw REPL string.

And if that is the case, it suggests that the data variable contains a tuple with two byte strings, instead of having just a byte string, no?

(b'hello\r\nMicroPython v1.18 on 2022-01-17; 4MB/OTA module with ESP32\r\nType "help()" for more information.\r\n>>> ',b'raw REPL; CTRL-B to exit\r\n>')

But if that was true, then the if not data.endswith(msg) line of code from the flush_to_msg() function would have thrown an exception? As data would be a tuple, and tuples don't have the endswith() method.

microfs/microfs.py

Lines 66 to 72 in db5e7b2

def flush_to_msg(serial, msg):
"""Read the rx serial data until we reach an expected message."""
data = serial.read_until(msg)
if not data.endswith(msg):
if COMMAND_LINE_FLAG:
print(data)
raise IOError("Could not enter raw REPL. %s" % data)

Something doesn't quite add up with my analysis here, so I'm not too sure where the root of the problem lays yet.

@carlosperate
Copy link
Contributor

carlosperate commented Jan 13, 2023

The other log lines root:70(flush_to_msg) also print the data variable, and in all cases they are tuples instead of byte strings.
But that really doesn't explain how the line if not data.endswith(msg): doesn't throw an exception.

Also, if data was a tuple, "Could not enter raw REPL. %s" % data would throw an exception as well:

>>> data = (b'hello\r\nMicroPython v1.18 on 2022-01-17; 4MB/OTA module with ESP32\r\nType "help()" for more information.\r\n>>> ',b'raw REPL; CTRL-B to exit\r\n>')
>>> print("Could not enter raw REPL. %s" % data)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    print("Could not enter raw REPL. %s" % data)
TypeError: not all arguments converted during string formatting

@gschaden can we compare the log of successfull and unsuccessfull run? Is the data type of the variable data different in those two cases?

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

Successfully merging this pull request may close these issues.

3 participants