Skip to content

Assign codes to errors #673

Closed
Closed

Description

@RubenVerborgh

Problem

We want there to be nice error reporting toward users (#654).

An issue is that the connection between the problem and possible solutions is not always obvious.
This is because the component generating the error is not aware of its role in the bigger configuration.


Example

For example, if run CSS behind a proxy but forget to set up the Forwarded header, then requests to the server will be made with the wrong hostname and/or protocol. This results in the error:

InternalServerError: http://wrong.host/ is not supported
    at SingleRootIdentifierStrategy.getParentContainer (/Users/ruben/Documents/UGent/Solid/solid-community-server/dist/util/identifiers/BaseIdentifierStrategy.js:14:19)
    at WebAclAuthorizer.getAclRecursive (/Users/ruben/Documents/UGent/Solid/solid-community-server/dist/authorization/WebAclAuthorizer.js:186:48)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async WebAclAuthorizer.handle (/Users/ruben/Documents/UGent/Solid/solid-community-server/dist/authorization/WebAclAuthorizer.js:41:23)
    at async AuthenticatedLdpHandler.runHandlers (/Users/ruben/Documents/UGent/Solid/solid-community-server/dist/ldp/AuthenticatedLdpHandler.js:75:35)
    at async AuthenticatedLdpHandler.handle (/Users/ruben/Documents/UGent/Solid/solid-community-server/dist/ldp/AuthenticatedLdpHandler.js:46:61)
    at async SequenceHandler.handle (/Users/ruben/Documents/UGent/Solid/solid-community-server/dist/util/handlers/SequenceHandler.js:27:26)
    at async Server.<anonymous> (/Users/ruben/Documents/UGent/Solid/solid-community-server/dist/server/BaseHttpServerFactory.js:25:17)

For SingleRootIdentifierStrategy, it is impossible to know what the actual issue is, and WebAclAuthorizer does not have any clue either.

What we want (after #654), is an error page such as:

Requests to http://wrong.host/ are not supported

The Community Solid Server received a request for http://wrong.host/, which is not configured.
Here are some things you can try to fix this:

  • Have you started the server with the right hostname?
  • If you are running the server behind a reverse proxy, did you set up the Forwarded header correctly?

Proposal

Errors should be assigned codes, something like E1234, such that we can easily recognize them later on.

We could do things like:

  • have a file with a list of constants (enum?) that are error codes
    • something like export const ERROR_UNSUPPORTED_IDENTIFIER = createErrorType('E1234');
    • or ErrorCodes.UnsupportedIdentifier (perhaps simlar to the namespaces code we have)
  • have a specific Error subtype that takes such an error code in its constructor
  • or even have a custom error class for every error we emit; the class definition then has the error code
    • something like export const UnsupportedIdentifierError = createErrorType('E1234');

Activity

  1. jvherweg commented on Mar 26, 2021

    @jvherweg
    Member

    Any reason why the code should be something like E1234 and not just UNSUPPORTED_IDENTIFIER?

    This issue feels similar to the problem we initially had on how to link status codes to errors, which we solved by going for the custom error classes for every status code. In case we go for solution 1-2 here, there's something to be said to also determine status code based on those constants so we don't have 2 different solutions internally for the same problem.

  2. RubenVerborgh commented on Mar 26, 2021

    @RubenVerborgh
    MemberAuthor

    Any reason why the code should be something like E1234 and not just UNSUPPORTED_IDENTIFIER?

    I was just following TypeScript errors etc. there; to not put too much meaning into the identifier.

    there's something to be said to also determine status code based on those constants so we don't have 2 different solutions internally for the same problem.

    Absolutely.

  3. jvherweg commented on Jun 22, 2021

    @jvherweg
    Member

    The solution here depends on bit on what we exactly want and need. The example error above is a good example of an error where more information should be provided to client, but how many such errors do we have compared to the total amount of different errors that are being thrown?

    In case we only have a few errors for which we want to provide more context and information we could create new error classes specifying that. We could have a BadIdentifierError that extends the InternalServerError and has a more extensive description internally. This could be a specific type of DescriptiveError which has more fields than a normal error. We would then also update the error handlers and converter to make sure those fields are supported. But most of the errors we have would stay as they are now, this is assuming only a few would need this.

    Another solution is similar to the above but instead of storing the extra fields in the error object we store them somewhere externally (like JSON) and the error handler would then check that resource every time it sees such a special error. We would also need a way to handle variables, so some sort of template might be needed.

    The most drastic solution would be similar to the above, but apply it to all errors that we throw. In that case I would suggest only having 1 error class anymore, because otherwise we would almost need a new class for every error that we throw. All error messages/status codes/extra descriptions would then be stored in a single JSON document (or multiple, to allow extension). I think something similar was also suggested initially when talking about how to do errors (and is bullet point 2 in the top message).

    Some disadvantages of the last solution are that we lose typing, unless we store information in a typescript file instead of an external JSON. It might also make it more difficult for external packages that want to throw a new type of error. Would depend on how we handle configuration for this. It would make localization easier should that ever be necessary.

    I did a count and we currently throw errors on 180 different places. Besides the 404 errors I'm assuming that all those errors have unique error messages. So in case we want to replace all of them that would be a lot of entries. I'm also afraid that keeping the error descriptions in sync with what errors are needed might be an issue.

  4. RubenVerborgh commented on Jun 25, 2021

    @RubenVerborgh
    MemberAuthor

    Resolution after discussion:

    1. Let's ensure that all errors take two parameters; the first being a (short) description string, the second an optional hash that can take a cause parameter. Let's also allow an optional errorCode field in there.
    2. Let's keep the existing error classes as they are otherwise.

    A separate JSON document can, for some error codes, provide an extended (paragraph-size) description of how to fix it in the context of the entire server (whereas a local component would only know the local cause). Or they could even be Markdown documents ERR1234.md or even templates so we can render the above example.

    Over time, that separate JSON document could also per error code contain the HTTP status codes, thereby fully decoupling those as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions