Skip to content

Improve TD validation error in requestThingDescription#1404

Merged
relu91 merged 4 commits into
eclipse-thingweb:masterfrom
danielpeintner:issue-1403
Jul 29, 2025
Merged

Improve TD validation error in requestThingDescription#1404
relu91 merged 4 commits into
eclipse-thingweb:masterfrom
danielpeintner:issue-1403

Conversation

@danielpeintner
Copy link
Copy Markdown
Member

fixes #1403

@danielpeintner
Copy link
Copy Markdown
Member Author

Unfortunately, it is not possible to wrap an error in TS/JS.

@danielpeintner danielpeintner requested review from egekorkan and relu91 and removed request for relu91 June 25, 2025 09:44
@danielpeintner danielpeintner changed the title refactor: extend TD validation error Improve TD validation error in requestThingDescription Jun 25, 2025
@relu91
Copy link
Copy Markdown
Member

relu91 commented Jun 25, 2025

Unfortunately, it is not possible to wrap an error in TS/JS.

You should be able to define custom errors.

export class ValidationError extends Error {

  public constructor(input: ??) {
    //... 
  }
}

or did I miss your point?

@danielpeintner
Copy link
Copy Markdown
Member Author

What I meant was wrapping this error in another error to get a stack trace like in Java

@egekorkan
Copy link
Copy Markdown
Member

But this still makes me think that there is a TD validation error. The request method should be catched?

@relu91
Copy link
Copy Markdown
Member

relu91 commented Jun 25, 2025

Yeah, in the case you described in the issue, the client.requestThingDescription should fail... the problem is here:
https://github.com/eclipse-thingweb/node-wot/blob/master/packages/binding-http/src/http-client-impl.ts#L249

We are not checking the result (e.g., 404 or any other error condition).

Unless the URL you provided actually answers with a JSON payload... in that case the error is correct IMHO.

@danielpeintner
Copy link
Copy Markdown
Member Author

The issue happen in the following code

if (isThingDescription(value)) {
return value;
}
throw getLastValidationErrors();

Line99 returns false and hence Line103 throws the TD validation issue.
In @egekorkan case it just says "Error: must be object" which is not clear "what" should be an object.

What I do in my PR is essentially just extending the error (with "TD validation error: ") so that it is clear what the error is about. In this case, the TD is not valid.
Not sure what you expect me to do...

@egekorkan
Copy link
Copy Markdown
Member

In this case, the TD is not valid.

No in this case there is no TD to begin with. The link @relu91 sent makes sense as there is no handling of request not resolving

@danielpeintner
Copy link
Copy Markdown
Member Author

How do I know whether the result is a TD? We have the isThingDescription(...) call for that, right.

In your case, the issue is not that we get a 404 (in such a case you get a 404 message). The issue is that you get a result .. in this case, a JSON array as response...

@relu91
Copy link
Copy Markdown
Member

relu91 commented Jun 26, 2025

The issue is that you get a result .. in this case, a JSON array as response...

As I said above, if this is the case, the answer @egekorkan described in the issue is indeed correct.

@danielpeintner
Copy link
Copy Markdown
Member Author

I seem to be on the wrong track somehow!? 🤷‍♂️

Can you explain to me what you ask me to do? Or do you want to propose a fix?

Yes, we get an array as response, and I do know that this can never be a TD.
Sure, I can add a type check .. but why should I do that in the node-wot code if the code we are calling ( i.e., isThingDescription(...)) is doing that already.

Hence, I only add to the error message we are getting the information that the error is caused be the TD validation... so that developers better understand what the error is about.

@relu91
Copy link
Copy Markdown
Member

relu91 commented Jun 26, 2025

I seem to be on the wrong track somehow!?

No, you are correct! I was saying that since we are receiving a valid json (and not a 404 or other error codes like a timeout) the error that we are throwing is correct, we can improve as you are doing here, but I would not even bother (but we can move on if you like).

@danielpeintner
Copy link
Copy Markdown
Member Author

I will take a closer look at the possible error cases and look also into client.requestThingDescription(url) and check whether a HTTP status >= 400 throws an error also

@danielpeintner
Copy link
Copy Markdown
Member Author

danielpeintner commented Jun 30, 2025

Commit 9afaaf2 should add the information needed if an HTTP error happens...

@danielpeintner
Copy link
Copy Markdown
Member Author

I think this brings up a new issue

https://github.com/eclipse-thingweb/node-wot/actions/runs/15978405985/job/45066738871?pr=1404#step:9:310

I think it should be handled by the following part already but it doesn't seem to be the case

if (HttpClient.isOAuthTokenExpired(result, this.credential)) {

@danielpeintner
Copy link
Copy Markdown
Member Author

I think it should be handled by the following part already but it doesn't seem to be the case

if (HttpClient.isOAuthTokenExpired(result, this.credential)) {

It is not a OAuth error but a generic unauthorized error... I added a special case for it to make the following test happy.

error.message.should.eql("Client error: Unauthorized");

@danielpeintner
Copy link
Copy Markdown
Member Author

Anything missing?
@relu91 @egekorkan

Copy link
Copy Markdown
Member

@relu91 relu91 left a comment

Choose a reason for hiding this comment

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

LGTM, as discussed in call. Let's merge it.

@relu91 relu91 merged commit 8cd451b into eclipse-thingweb:master Jul 29, 2025
11 checks passed
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.

Wrong TD URL returns invalid TD error

3 participants