-
Notifications
You must be signed in to change notification settings - Fork 95
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
Unify Error Throwing Methods #696
Comments
Could I give it a try? |
@gwbaik9717 Sure! Happy to see you doing error related issues again. |
I'm considering solving this issue as follows. Please review and let me know if it is alright. I believe the I suggest logging messages with the After the change, there will be only two scenarios in logging and throwing errors:
throw new YorkieError(Code.ErrInvalidArgument, ERROR_MESSAGE);
// src/util/logger.ts
export const logger = {
fatal: (message: string, ...messages: Array<unknown>): void => {
if (typeof console !== 'undefined') {
if (typeof console.error !== 'undefined') {
console.error('YORKIE F:', ...messages);
} else {
console.log('YORKIE F:', ...messages);
}
}
// throw error removed
},
// Other log levels like debug, info, warn, error, etc.
};
const ERROR_MESSASGE = "This is a fatal error."
logger.fatal(ERROR_MESSAGE);
throw new YorkieError(Code.ErrInvalidArgument, ERROR_MESSAGE); In this way, I believe we can solve the type problem of the logger function, and users will be explicitly aware when an error is being thrown. |
@gwbaik9717 Thank you for sharing your approach. As you suggested, it would be good to standardize the error handling by throwing custom cc. @hackerwins |
Description:
yorkie-js-sdk
uses three different methods for throwing errors. Let's pick one way to throw errors and apply it consistently acrossyorkie-js-sdk
. If there's a better approach, let's talk about it and see if we should switch.throw new Error
:Generates a general error using the
throw
statement. This is a straightforward and common method.throw new YorkieError
:Creates and throws a custom error, allowing additional information to be added to the error. This approach helps identify errors originating from Yorkie, provides a way to categorize errors, but requires handling of error codes for each case.
logger.fatal()
:Records errors using the
logger
with thefatal
level. Different processing can be applied based on log levels.However, note that an error is being thrown within
logger.fatal
. This can lead to TypeScript errors when using the method, as showed in the example below:Why:
Standardize the error-throwing approach for consistency and clarity throughout the
yorkie-js-sdk
codebase.The text was updated successfully, but these errors were encountered: