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

Please export EtaError type #243

Closed
xuxucode opened this issue Jul 1, 2023 · 5 comments
Closed

Please export EtaError type #243

xuxucode opened this issue Jul 1, 2023 · 5 comments

Comments

@xuxucode
Copy link

xuxucode commented Jul 1, 2023

Is your feature request related to a problem? Please describe.

We are using eta to render message codes (as named templates) to localized messages. Since there many message codes exist, lazy loading templates is decided. For example:

try {
  eta.render('@username_already_exists', { username: 'something' })
} catch (err) {
  if (err instanceof EtaError) { // Cannot find name 'EtaError'
                        ^
    eta.loadTemplate('@username_already_exists', '<%= it.username %> already exists.')
  }
  // render again
}

Describe the solution you'd like

Please export the EtaError, or export a more specific error, EtaTemplateNotFoundError for example.

@nebrelbug
Copy link
Collaborator

@xuxucode this seems like a good idea which I'll try to release soon. Do you think it would be helpful to have separate errors for different kinds of bugs, or is it sufficient to have just one exported error type?

@xuxucode
Copy link
Author

xuxucode commented Jul 4, 2023

Thanks. It's helpful to have separate errors, my 2 cents:

  • EtaFileTempalteError: views not set, file path cannot be resolved, file not found
  • EtaNamedTempalteError: named template not defined(loaded),
  • EtaParseError: parsing template content failed
  • EtaRuntimeError: runtime errors

@nebrelbug
Copy link
Collaborator

@xuxucode thanks for the input! I'll wait for a few days before working on this to see if others have feedback.

@nebrelbug
Copy link
Collaborator

I think this is a good idea. Desired behavior should be that Eta throws 4 different errors, each extended from one base Eta class:

  • EtaFileResolutionError
  • EtaNameResolutionError
  • EtaParseError
  • EtaRuntimeError

I don't have time to implement this right now, but anyone is welcome to submit a PR with this behavior.

@nebrelbug
Copy link
Collaborator

Closed by #276 🚀

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

No branches or pull requests

2 participants