Fix Read Textfile bug and output python errors to console

This commit is contained in:
Melissa LeBlanc-Williams 2024-06-19 10:18:56 -07:00
parent 2d3c372cd4
commit 09808e3fe7
3 changed files with 14 additions and 11 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "@adafruit/circuitpython-repl-js",
"version": "1.2.3",
"version": "2.0.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@adafruit/circuitpython-repl-js",
"version": "1.2.3",
"version": "2.0.1",
"license": "MIT",
"devDependencies": {}
}

View file

@ -3,7 +3,7 @@
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"version": "1.2.3",
"version": "2.0.1",
"description": "A JavaScript Module to help with interfacing to the REPL on CircuitPython Devices over serial",
"main": "repl.js",
"exports": {

19
repl.js
View file

@ -64,10 +64,13 @@ export class FileOps {
async _checkReplErrors() {
let error = this._repl.getErrorOutput();
if (error && error.type == "OSError" && error.errno == 30) {
this._isReadOnly = true;
// Throw an error if needed
await this._checkReadOnly();
if (error) {
console.error("Python Error - " + error.type + ": " + error.message);
if (error.type == "OSError" && error.errno == 30) {
this._isReadOnly = true;
// Throw an error if needed
await this._checkReadOnly();
}
}
return error;
@ -162,11 +165,11 @@ with open("${path}", "rb") as f:
async _readTextFile(path) {
try {
let code = `
with open("${path}", "r") as f:
print(f.read())
`;
with open("${path}", "r") as f:
print(f.read())
`;
let result = await this._repl.execRawPasteMode(code);
if (this._checkReplErrors()) {
if (await this._checkReplErrors()) {
return null;
}