You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Open reproduction repo, disregard error in the main terminal, open new terminal.
Try running node ace, you will get a TypeError: vine.string(...).regex(...).assume is not a function error.
Go to #bin/console.ts and uncomment workaround (import start/validator)
Repeat node ace - now executes without an error.
Implementation notes:
start/validator - preload file which registers custom validator macro.
app/validators/ping - custom shared validator which uses registered macro.
commands/ping - command which is configured to boot application and uses shared validator.
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:
Preload - not included during ace command bootstrap.
Provider boot/register - too late (not sure why).
Questions:
Is it a valid bug, or ace is designed to skip preloads? Is it documented somewhere?
What is recommended place to register macros? Preload or provider?
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:
node ace
, you will get aTypeError: vine.string(...).regex(...).assume is not a function
error.#bin/console.ts
and uncomment workaround (import start/validator
)node ace
- now executes without an error.Implementation notes:
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:
Questions:
Reproduction repo
https://codesandbox.io/p/github/qodeboy/adonis-ace-validator-bug/main
The text was updated successfully, but these errors were encountered: