cel-go icon indicating copy to clipboard operation
cel-go copied to clipboard

Error message and trace translations

Open vivshankar opened this issue 5 years ago • 3 comments

Feature request checklist

  • [ x ] There are no issues that match the desired change
  • [ x ] The change is large enough it can't be addressed with a simple Pull Request

Change I am using CEL as a rule compute engine within my product. I have a need to be able to provide translated error messages to users and am wondering if there is any way for this to be accomplished in CEL. I am happy to inject the translation files in my code, if a mechanism exists.

Happy to submit a pull request if some pointers can be given.

Example Undeclared reference to 'test' (in container '')

Ideally, I would like to be able to translate messages of this sort.

Alternatives considered N/A

vivshankar avatar Aug 31 '20 14:08 vivshankar

Hi @vivshankar, if you'd like to contribute here, I can offer you some advice for the parser and checker errors in a manner that permits the use of alternative language for the error message information. Would that work for your needs?

The runtime errors are in need of love and #25 and #189 are the specific changes that need to improve runtime stack traces and error messaging.

TristonianJones avatar Sep 02 '20 16:09 TristonianJones

@TristonianJones Happy to take a shot at this.

vivshankar avatar Sep 03 '20 12:09 vivshankar

@vivshankar Thanks for being patient on this. I spent a little time thinking about this the other day and both the parser/errors.go and the checker\errors.go introduce an abstraction layer between the parser / checker and the common.Errors object. These minor abstractions introduce standard error messages and formats for each component.

My recommendation is as follows:

  1. Introduce a Localizer interface in the common/localizer (new) package.
type Localizer interface {
  Localize(int msgID, args ...interface{})
}
  1. Establish constants for the existing English messages in common/localizer/codes.go and a mapping from the message id to a struct containing the localized message and the number of expected arguments to the message for the sake of linting. This first mapping for English can be in common/localizer/en_us.go
  2. Create functional options for configuring the localizer for the parser and checker which adjust the localizer used when creating the parserErrors and checkerErrors objects.

This will probably take a bit of time to do, but the above is the rough idea. Please feel free to ask questions as you work through the code.

TristonianJones avatar Sep 14 '20 17:09 TristonianJones