-
-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add implementation-check on startup #155
Comments
I'm not sure about this... What would the catch blocks do? Just report that the error was raised in the implementation? You can already see this in the stack trace generated by a thrown error. |
Yes, I can see that. But when I get a question from someone else who is trying to implement it I often don't have the stack trace. It is mostly something like |
Could you provide an example of how the catch block might look like? I'm a bit concerned that this might make debugging even harder as there is a risk that it swallows the actual error or obscures debug information (in particular the stack trace) that could be useful. |
The example is the get-method of the ContentTypeCache. If With the try/catch block we could throw something like: public async get(...machineNames: string[]): Promise<ContentType[]> {
try {
if (!machineNames || machineNames.length === 0) {
return this.storage.load('contentTypeCache');
}
return (await this.storage.load('contentTypeCache')).filter(
(contentType: ContentType) =>
machineNames.some(
(machineName: string) =>
machineName === contentType.machineName
)
);
} catch (error) {
log(error);
throw new Error(
'Missing load-method on content-storage. Please make sure your implementation of the ContentStorage is correct. For more information see..'
);
}
} |
Another idea would be to check the implementations on startup and throw errors there. Something like an implementation-validator that checks if everything works. But it is just an idea. |
I would prefer the implementation check on startup (or some test cases that you can run?). In the example above the catch block would throw the error message regardless of what goes wrong, which might be something different than just a missing load method. It could be an error in the database of the implementation, an error in our code etc. All of this is obscured by the catch statement, and I think giving a proper error message is impossible. |
In order to improve the development we have to make sure, that reported errors are not in fact a wrong implementation.
So we should have something like try/catch blocks around calls to the implementations and check if they fail.
Or is there a better way?
The text was updated successfully, but these errors were encountered: