eta-dev / eta

Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript
https://eta.js.org
MIT License
1.35k stars 60 forks source link

Please export EtaError type #243

Closed xuxucode closed 3 months ago

xuxucode commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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

nebrelbug commented 1 year ago

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

nebrelbug commented 11 months ago

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

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

nebrelbug commented 3 months ago

Closed by #276 :rocket: