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

Preloads not being loaded during ace command execution #4858

Open
qodeboy opened this issue Jan 18, 2025 · 0 comments
Open

Preloads not being loaded during ace command execution #4858

qodeboy opened this issue Jan 18, 2025 · 0 comments

Comments

@qodeboy
Copy link

qodeboy commented Jan 18, 2025

Package version

@adonisjs/[email protected]

Describe the bug

Preloads and/or validator macros are not loaded in ace commands lifecycle.

Reproduction repo: https://codesandbox.io/p/github/qodeboy/adonis-ace-validator-bug/main

Steps:

  1. Open reproduction repo, disregard error in the main terminal, open new terminal.
  2. Try running node ace, you will get a TypeError: vine.string(...).regex(...).assume is not a function error.
  3. Go to #bin/console.ts and uncomment workaround (import start/validator)
  4. Repeat node ace - now executes without an error.

Implementation notes:

  1. start/validator - preload file which registers custom validator macro.
  2. app/validators/ping - custom shared validator which uses registered macro.
  3. commands/ping - command which is configured to boot application and uses shared validator.
  4. bin/console - is where current workaround is implemented.

Breakdown:

Sometimes we need to use a validator (will all extension/macros we configured) outside of HTTP context. Valid use cases is validation in ace commands or background/queue jobs. But the issue is that macros registered using preload is not being picked up when app is started in ace context.

This results in runtime errors when trying to use shared validator which use macros/extensions. Current workaround is to manually import validator preload inside bin/console file, but this feels dirty.

Solutions I have tried:

  1. Preload - not included during ace command bootstrap.
  2. Provider boot/register - too late (not sure why).

Questions:

  1. Is it a valid bug, or ace is designed to skip preloads? Is it documented somewhere?
  2. What is recommended place to register macros? Preload or provider?

Reproduction repo

https://codesandbox.io/p/github/qodeboy/adonis-ace-validator-bug/main

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

1 participant