Skip to content

Commit 62eca73

Browse files
refactor: improve logging and comments
1 parent 57adde7 commit 62eca73

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/Device.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ class Device {
118118
subscribe(() => this.onChanged());
119119

120120
this.busy.subscribe((val) => this.log.debugShort(val ? "busy..." : "idle."));
121+
this.busy.subscribe(
122+
(isBusy) =>
123+
!isBusy &&
124+
this.adapter.__proxyMeta.isBusy &&
125+
this.log.error(
126+
"Device is not busy, but the adapter queue is active. Current task:",
127+
[...this.adapter.__proxyMeta.history].pop()
128+
)
129+
);
121130

122131
this.readUntil = createReadUntil();
123132
this.readUntil(/\n>>> [^\n]*$/, (matches) => this.busy.set(!matches), { callOnFalse: true });
@@ -231,7 +240,7 @@ class Device {
231240
*/
232241
async runScript(script, options) {
233242
options = Object.assign({}, runScriptDefaults, options);
234-
this.log.debug(`runScript:\n\n${script}\n\n`);
243+
this.log.debug(`queued runScript:\n\n${script}\n\n`);
235244
this.busy.set(true);
236245
const start = Date.now();
237246
const result = await this.adapter.runScript(script + "\n\r\n\r\n", options);
@@ -497,6 +506,7 @@ class Device {
497506
* }} options
498507
*/
499508
async upload(source, destination, options) {
509+
this.log.debug("upload", source, "to", destination);
500510
destination = posix.join(this.config.rootPath, destination.replace(/[\/\\]+/g, "/"));
501511
await this.adapter.mkdirs(dirname(destination));
502512

src/providers/FilesystemProvider.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ class FileSystemProvider {
2727
return await device.adapter.remove(uri.path, isDir);
2828
} catch (err) {
2929
if (err.message.endsWith(" ENOENT")) throw vscode.FileSystemError.FileNotFound(`Could not find '${uri.path}'.`);
30-
else this.pymakr.notifier.notifications.uncaughtError(err)
30+
else this.pymakr.notifier.notifications.uncaughtError(err);
3131
}
3232
}
3333

3434
watch(uri, options) {
3535
// todo?
36-
return new vscode.Disposable(() => { });
36+
return new vscode.Disposable(() => {});
3737
}
3838

3939
async rename(oldUri, newUri) {
@@ -50,7 +50,7 @@ class FileSystemProvider {
5050
* @param {vscode.Uri} uri
5151
*/
5252
async readFile(uri) {
53-
this.log.debug('read file', uri)
53+
this.log.debug("read file", uri);
5454
const device = this._getDevice(uri);
5555
return device.adapter.getFile(uri.path);
5656
}

src/stores/devices.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { SerialPort } = require("serialport");
1010
*/
1111
const rawSerialToDeviceInput = (raw) => ({
1212
address: raw.path,
13-
name: raw.friendlyName || raw.path.replace(/^\/dev\//, ''),
13+
name: raw.friendlyName || raw.path.replace(/^\/dev\//, ""),
1414
protocol: "serial",
1515
id: raw.serialNumber,
1616
raw,
@@ -60,7 +60,7 @@ const createDevicesStore = (pymakr) => {
6060
);
6161

6262
const registerUSBDevices = async () => {
63-
pymakr.log.traceShort("register USB devices");
63+
pymakr.log.trace("register USB devices");
6464
const rawSerials = await SerialPort.list();
6565
const deviceInputs = rawSerials.map(rawSerialToDeviceInput);
6666
const inputIds = deviceInputs.map((deviceInput) => deviceInput.id);

0 commit comments

Comments
 (0)