Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default defineConfig([
"@typescript-eslint/no-require-imports": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
"@typescript-eslint/prefer-nullish-coalescing": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
"@typescript-eslint/no-empty-object-type": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
"@typescript-eslint/no-floating-promises": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
"@typescript-eslint/no-floating-promises": "error",

// **************** Enforce usage of `const` over `let` wherever possible, to prevent accidental reassignments
"prefer-const": "error",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/consumed-thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class InternalEventSubscription extends InternalSubscription {

const formWithoutURIvariables = handleUriVariables(this.thing, te, form, options);
debug(`ConsumedThing '${this.thing.title}' unsubscribing to ${form.href}`);
this.client.unlinkResource(formWithoutURIvariables);
await this.client.unlinkResource(formWithoutURIvariables);
this.active = false;
}

Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/exposed-thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,9 @@ export default class ExposedThing extends TD.Thing implements WoT.ExposedThing {
}
const unsubscribe = this.#eventHandlers.get(name)?.unsubscribe;
if (unsubscribe) {
unsubscribe(options);
unsubscribe(options).catch((error) => {
throw error;
});
}
debug(`ExposedThing '${this.title}' unsubscribes from event '${name}'`);
} else {
Expand Down Expand Up @@ -663,7 +665,9 @@ export default class ExposedThing extends TD.Thing implements WoT.ExposedThing {

const unobserveHandler = this.#propertyHandlers.get(name)?.unobserveHandler;
if (unobserveHandler) {
unobserveHandler(options);
unobserveHandler(options).catch((error) => {
throw error;
});
}
} else {
throw new Error(`ExposedThing '${this.title}', no property found for '${name}'`);
Expand Down
26 changes: 18 additions & 8 deletions packages/core/src/protocol-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,27 @@ export default class ProtocolHelpers {
const reader = stream.getReader();
const result = new ManagedReadable({
read: (size) => {
reader.read().then((data) => {
result.push(data.value);
if (data.done) {
// signal end
result.push(null);
}
});
reader
.read()
.then((data) => {
result.push(data.value);
if (data.done) {
// signal end
result.push(null);
}
})
.catch((error) => {
throw error;
});
},
destroy: (error, callback) => {
reader.releaseLock();
stream.cancel(error).then(() => callback(error));
stream
.cancel(error)
.then(() => callback(error))
.catch((error) => {
throw error;
});
},
});
result.wotStream = stream as ReadableStream;
Expand Down
65 changes: 44 additions & 21 deletions packages/core/test/client-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,14 @@ class WoTClientTest {
this.clientFactory = new TrapClientFactory();
this.servient.addClientFactory(this.clientFactory);
this.servient.addClientFactory(new TDClientFactory());
this.servient.start().then((myWoT) => {
this.WoT = myWoT;
});
this.servient
.start()
.then((myWoT) => {
this.WoT = myWoT;
})
.catch((error) => {
throw error;
});
debug("started test suite");
}

Expand Down Expand Up @@ -570,11 +575,17 @@ class WoTClientTest {
expect(thing).to.have.property("title").that.equals("aThing");
expect(thing).to.have.property("events").that.has.property("anEvent");
return new Promise((resolve) => {
thing.subscribeEvent("anEvent", async (x) => {
const value = await x.value();
expect(value).to.equal("triggered");
resolve(true);
});
thing
.subscribeEvent("anEvent", async (x) => {
const value = await x.value();
expect(value).to.equal("triggered");
resolve(true);
})
.catch((error) => {
throw error;
});
}).catch((error) => {
throw error;
});
}

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

const subscription = await thing.subscribeEvent("anEvent", () => {
/** */
});
const subscription = await thing
.subscribeEvent("anEvent", () => {
/** */
})
.catch((error) => {
throw error;
});
await subscription.stop();

return new Promise((resolve) => {
thing.subscribeEvent("anEvent", async (x) => {
const value = await x.value();
expect(value).to.equal("triggered");
resolve(true);
});
thing
.subscribeEvent("anEvent", async (x) => {
const value = await x.value();
expect(value).to.equal("triggered");
resolve(true);
})
.catch((error) => {
throw error;
});
});
}

Expand All @@ -649,11 +668,15 @@ class WoTClientTest {
expect(thing).to.have.property("title").that.equals("aThing");
expect(thing).to.have.property("properties").that.has.property("aPropertyToObserve");
return new Promise((resolve) => {
thing.observeProperty("aPropertyToObserve", async (data) => {
const value = await data.value();
expect(value).to.equal(12);
resolve(true);
});
thing
.observeProperty("aPropertyToObserve", async (data) => {
const value = await data.value();
expect(value).to.equal(12);
resolve(true);
})
.catch((error) => {
throw error;
});
});
}

Expand Down
19 changes: 14 additions & 5 deletions packages/core/test/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ class WoTServerTest {
this.servient = new Servient();
this.server = new TestProtocolServer();
this.servient.addServer(this.server);
this.servient.start().then((WoTruntime) => {
this.WoT = WoTruntime;
});
this.servient
.start()
.then((WoTruntime) => {
this.WoT = WoTruntime;
})
.catch((error) => {
throw error;
});
debug("started test suite");
}

Expand Down Expand Up @@ -889,7 +894,9 @@ class WoTServerTest {

thing.setPropertyReadHandler("test", callback);

(thing as ExposedThing).handleObserveProperty("test", protocolListener, { formIndex: 0 });
(thing as ExposedThing).handleObserveProperty("test", protocolListener, { formIndex: 0 }).catch((error) => {
throw error;
});

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

Expand Down Expand Up @@ -964,7 +971,9 @@ class WoTServerTest {
thing.setEventSubscribeHandler("test", handler);
await (<ExposedThing>thing).handleSubscribeEvent("test", callback, { formIndex: 0 });
(<ExposedThing>thing).emitEvent("test", null);
(<ExposedThing>thing).handleUnsubscribeEvent("test", callback, { formIndex: 0 });
(<ExposedThing>thing).handleUnsubscribeEvent("test", callback, { formIndex: 0 }).catch((error) => {
throw error;
});
(<ExposedThing>thing).emitEvent("test", null);

return expect(callback).to.have.been.called.once;
Expand Down
Loading