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

Compiler swallows Errors thrown in CompilerPasses #208

Open
fcaps opened this issue Nov 30, 2023 · 2 comments
Open

Compiler swallows Errors thrown in CompilerPasses #208

fcaps opened this issue Nov 30, 2023 · 2 comments
Labels

Comments

@fcaps
Copy link

fcaps commented Nov 30, 2023

Hey,

don't know if this was by mistake, but the Compiler is swallowing all Errors other than RangeError, took me a while to debug this.

  async run () {
    try {
      if (!this._container.frozen) {
        await this._loadExtensions()
        await this._optimize()
        await this._remove()
      }
    } catch (error) {
      if (error instanceof RangeError) {
        throw new ServiceCircularReferenceException()
      }
    }
  }

the original compile from was re-throwing:

  compile () {
    try {
      if (!this.frozen) {
        this._loadExtensions()
        this._optimize()
        this._remove()
      }
    } catch (error) {
      if (error instanceof RangeError) {
        throw new ServiceCircularReferenceException()
      }

      throw error
    }
  }

looking at the code, compiling a frozen container should also thrown an Error imo.

@zazoomauro
Copy link
Owner

@fcaps Is so strange... all this errors are covered by lot of tests.

@fcaps
Copy link
Author

fcaps commented Dec 13, 2023

@zazoomauro when I "fix" the issue, some tests fail with a ServiceNotFoundException.
was not looking at other tests, but chances are high that they throw a RangeError or something.
image

here a quick test:

//ContainerBuilder.spec.js
    chai.use(require('chai-as-promised'))

    it('should re-throw errors from failing compiler pass', async () => {

        class CompilerPass {
            async process () {
                throw Error('catch me if you can')
            }
        }

        container.addCompilerPass(new CompilerPass())

        await expect(container.compile()).to.be.rejectedWith(Error)
    })

@zazoomauro zazoomauro added the bug label Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants