Wouldn't it be more appropriate to throw an exception? #2492
Replies: 3 comments 3 replies
-
Since Remix should be the one writing/encoding the cookie, the decode should never fail. It should only fail if somebody has tampered with the cookie. So instead of throwing an error, it simply ignores the invalid cookie and returns an empty object. I believe there was an error with the |
Beta Was this translation helpful? Give feedback.
-
I still think we should add some logging when an error is caught. The assumption that Cookies could be set by developers or other third-party libraries. It’s difficult for beginners who are not familiar with how Remix handles cookies to debug without proper error logs. I can open a PR for this, but I need some suggestion what kind of message we should leave ? function decodeData(value: string): any {
try {
return JSON.parse(decodeURIComponent(myEscape(atob(value))));
} catch (error: unknown) {
// some message like this ?
console.error(`Can not parse following cookie value: ${value}`, error)
return {};
}
} |
Beta Was this translation helpful? Give feedback.
-
I totally don’t understand the point of What’s the main reason for refusing to add just one log message that could be helpful for developers? Why not ? It's frustrated to debug/figure out issues when there is NO ANY message, and you to google/re-read document ... Is it considered too verbose? I’m not trying to argue, just genuinely curious. Thanks for everything. |
Beta Was this translation helpful? Give feedback.
-
Wouldn't it be more appropriate to throw an exception?
Wouldn't it be more appropriate to throw an exception or print it to the console?
It took me a long time to find the reason for this because of a bug.
Error in JSON.parse().
Beta Was this translation helpful? Give feedback.
All reactions