Skip to content

Commit 388a07e

Browse files
committed
Merge branch 'issue-1430-typescript-eslint-no-floating-promises' of https://github.com/danielpeintner/thingweb.node-wot into danielpeintner-issue-1430-typescript-eslint-no-floating-promises
2 parents f05617a + c454306 commit 388a07e

6 files changed

Lines changed: 84 additions & 38 deletions

File tree

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default defineConfig([
124124
"@typescript-eslint/no-require-imports": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
125125
"@typescript-eslint/prefer-nullish-coalescing": "error",
126126
"@typescript-eslint/no-empty-object-type": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
127-
"@typescript-eslint/no-floating-promises": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
127+
"@typescript-eslint/no-floating-promises": "error",
128128

129129
// **************** Enforce usage of `const` over `let` wherever possible, to prevent accidental reassignments
130130
"prefer-const": "error",

packages/core/src/consumed-thing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class InternalEventSubscription extends InternalSubscription {
288288

289289
const formWithoutURIvariables = handleUriVariables(this.thing, te, form, options);
290290
debug(`ConsumedThing '${this.thing.title}' unsubscribing to ${form.href}`);
291-
this.client.unlinkResource(formWithoutURIvariables);
291+
await this.client.unlinkResource(formWithoutURIvariables);
292292
this.active = false;
293293
}
294294

packages/core/src/exposed-thing.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,9 @@ export default class ExposedThing extends TD.Thing implements WoT.ExposedThing {
595595
}
596596
const unsubscribe = this.#eventHandlers.get(name)?.unsubscribe;
597597
if (unsubscribe) {
598-
unsubscribe(options);
598+
unsubscribe(options).catch((error) => {
599+
throw error;
600+
});
599601
}
600602
debug(`ExposedThing '${this.title}' unsubscribes from event '${name}'`);
601603
} else {
@@ -663,7 +665,9 @@ export default class ExposedThing extends TD.Thing implements WoT.ExposedThing {
663665

664666
const unobserveHandler = this.#propertyHandlers.get(name)?.unobserveHandler;
665667
if (unobserveHandler) {
666-
unobserveHandler(options);
668+
unobserveHandler(options).catch((error) => {
669+
throw error;
670+
});
667671
}
668672
} else {
669673
throw new Error(`ExposedThing '${this.title}', no property found for '${name}'`);

packages/core/src/protocol-helpers.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,27 @@ export default class ProtocolHelpers {
215215
const reader = stream.getReader();
216216
const result = new ManagedReadable({
217217
read: (size) => {
218-
reader.read().then((data) => {
219-
result.push(data.value);
220-
if (data.done) {
221-
// signal end
222-
result.push(null);
223-
}
224-
});
218+
reader
219+
.read()
220+
.then((data) => {
221+
result.push(data.value);
222+
if (data.done) {
223+
// signal end
224+
result.push(null);
225+
}
226+
})
227+
.catch((error) => {
228+
throw error;
229+
});
225230
},
226231
destroy: (error, callback) => {
227232
reader.releaseLock();
228-
stream.cancel(error).then(() => callback(error));
233+
stream
234+
.cancel(error)
235+
.then(() => callback(error))
236+
.catch((error) => {
237+
throw error;
238+
});
229239
},
230240
});
231241
result.wotStream = stream as ReadableStream;

packages/core/test/client-test.ts

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,14 @@ class WoTClientTest {
358358
this.clientFactory = new TrapClientFactory();
359359
this.servient.addClientFactory(this.clientFactory);
360360
this.servient.addClientFactory(new TDClientFactory());
361-
this.servient.start().then((myWoT) => {
362-
this.WoT = myWoT;
363-
});
361+
this.servient
362+
.start()
363+
.then((myWoT) => {
364+
this.WoT = myWoT;
365+
})
366+
.catch((error) => {
367+
throw error;
368+
});
364369
debug("started test suite");
365370
}
366371

@@ -570,11 +575,17 @@ class WoTClientTest {
570575
expect(thing).to.have.property("title").that.equals("aThing");
571576
expect(thing).to.have.property("events").that.has.property("anEvent");
572577
return new Promise((resolve) => {
573-
thing.subscribeEvent("anEvent", async (x) => {
574-
const value = await x.value();
575-
expect(value).to.equal("triggered");
576-
resolve(true);
577-
});
578+
thing
579+
.subscribeEvent("anEvent", async (x) => {
580+
const value = await x.value();
581+
expect(value).to.equal("triggered");
582+
resolve(true);
583+
})
584+
.catch((error) => {
585+
throw error;
586+
});
587+
}).catch((error) => {
588+
throw error;
578589
});
579590
}
580591

@@ -626,17 +637,25 @@ class WoTClientTest {
626637
expect(thing).to.have.property("title").that.equals("aThing");
627638
expect(thing).to.have.property("events").that.has.property("anEvent");
628639

629-
const subscription = await thing.subscribeEvent("anEvent", () => {
630-
/** */
631-
});
640+
const subscription = await thing
641+
.subscribeEvent("anEvent", () => {
642+
/** */
643+
})
644+
.catch((error) => {
645+
throw error;
646+
});
632647
await subscription.stop();
633648

634649
return new Promise((resolve) => {
635-
thing.subscribeEvent("anEvent", async (x) => {
636-
const value = await x.value();
637-
expect(value).to.equal("triggered");
638-
resolve(true);
639-
});
650+
thing
651+
.subscribeEvent("anEvent", async (x) => {
652+
const value = await x.value();
653+
expect(value).to.equal("triggered");
654+
resolve(true);
655+
})
656+
.catch((error) => {
657+
throw error;
658+
});
640659
});
641660
}
642661

@@ -649,11 +668,15 @@ class WoTClientTest {
649668
expect(thing).to.have.property("title").that.equals("aThing");
650669
expect(thing).to.have.property("properties").that.has.property("aPropertyToObserve");
651670
return new Promise((resolve) => {
652-
thing.observeProperty("aPropertyToObserve", async (data) => {
653-
const value = await data.value();
654-
expect(value).to.equal(12);
655-
resolve(true);
656-
});
671+
thing
672+
.observeProperty("aPropertyToObserve", async (data) => {
673+
const value = await data.value();
674+
expect(value).to.equal(12);
675+
resolve(true);
676+
})
677+
.catch((error) => {
678+
throw error;
679+
});
657680
});
658681
}
659682

packages/core/test/server-test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ class WoTServerTest {
6868
this.servient = new Servient();
6969
this.server = new TestProtocolServer();
7070
this.servient.addServer(this.server);
71-
this.servient.start().then((WoTruntime) => {
72-
this.WoT = WoTruntime;
73-
});
71+
this.servient
72+
.start()
73+
.then((WoTruntime) => {
74+
this.WoT = WoTruntime;
75+
})
76+
.catch((error) => {
77+
throw error;
78+
});
7479
debug("started test suite");
7580
}
7681

@@ -889,7 +894,9 @@ class WoTServerTest {
889894

890895
thing.setPropertyReadHandler("test", callback);
891896

892-
(thing as ExposedThing).handleObserveProperty("test", protocolListener, { formIndex: 0 });
897+
(thing as ExposedThing).handleObserveProperty("test", protocolListener, { formIndex: 0 }).catch((error) => {
898+
throw error;
899+
});
893900

894901
await (<ExposedThing>thing).emitPropertyChange("test");
895902

@@ -964,7 +971,9 @@ class WoTServerTest {
964971
thing.setEventSubscribeHandler("test", handler);
965972
await (<ExposedThing>thing).handleSubscribeEvent("test", callback, { formIndex: 0 });
966973
(<ExposedThing>thing).emitEvent("test", null);
967-
(<ExposedThing>thing).handleUnsubscribeEvent("test", callback, { formIndex: 0 });
974+
(<ExposedThing>thing).handleUnsubscribeEvent("test", callback, { formIndex: 0 }).catch((error) => {
975+
throw error;
976+
});
968977
(<ExposedThing>thing).emitEvent("test", null);
969978

970979
return expect(callback).to.have.been.called.once;

0 commit comments

Comments
 (0)