Skip to content
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

In a production environment, panic! may not be a good choice. #54

Closed
RickSKy opened this issue Nov 6, 2023 · 5 comments · Fixed by #63
Closed

In a production environment, panic! may not be a good choice. #54

RickSKy opened this issue Nov 6, 2023 · 5 comments · Fixed by #63

Comments

@RickSKy
Copy link

RickSKy commented Nov 6, 2023

In a production environment, panic! may not be a good choice. Can we directly return the error message as a string, i.e., change the code from

panic!( "Failed to format a message for locale {} and id {}.\nErrors\n{:?}", lang, text_id, errors  ) 

to

Some(format!("Failed to format a message for locale {} and id {}.\nErrors\n{:?}",   lang, text_id, errors))
@XAMPPRocky
Copy link
Owner

Thank you for your issue! I believe there are try_ variants for when you want to avoid panics, can you provide a specific example of where you're running into this?

@RickSKy
Copy link
Author

RickSKy commented Nov 6, 2023

I want to encapsulate the use of LOCALES.lookup_with_args in a Linux service. Sometimes, due to programming negligence, the name of the arguments may be written incorrectly, but this will not result in a compilation error. Instead, it will cause a runtime crash, which is not very user-friendly. Implementing compilation errors might be difficult, but directly printing error messages is a better approach as it allows for easy identification of the error, without the need to run the program multiple times to see the crash information.

@RickSKy
Copy link
Author

RickSKy commented Nov 6, 2023

The mentioned try_ function has left me a bit confused. Does the library provide such a function? Could you please provide an example? Thank you.

@Syndelis
Copy link
Contributor

Even with try_ methods, it will still panic when no arguments are provided to messages expecting them (here). This method should definitely return a Result, instead.

@PPakalns
Copy link

Wanted to provide some feedback that this change is needed.

When hot reloading translations that has an invalid translation this panic is triggered even when calling try_ family method.

With #63 hot reloading even with invalid translations works nicely, i can handle error correctly. I am using this feature daily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants