Commit Graph
10 Commits
Author SHA1 Message Date
kay ozaki 7921fa5a19 typing.lua boolean-true default prevents mail_auth modules from being disabled
refs: https://github.com/KumoCorp/kumomta/pull/505
2026-04-29 12:06:35 +01:00
Wez Furlong 332595ee2a queue.lua: add typing to setup methods
We had an issue where a typo resulted in a relatively inscrutable
error at runtime:

```lua
local queue_helper =  queue_module:setup ('/opt/kumomta/etc/policy/queues.toml')
```

produced this:

```
problem initializing: call validate_config callback: runtime error: /opt/kumomta/share/policy-extras/queue.lua:602: bad argument #1 to 'for iterator' (table expected, got nil)
stack traceback:
        [C]: in function 'next'
        /opt/kumomta/share/policy-extras/queue.lua:602: in function </opt/kumomta/share/policy-extras/queue.lua:551>
Error: Initialization raised an error: call validate_config callback: runtime error: /opt/kumomta/share/policy-extras/queue.lua:602: bad argument #1 to 'for iterator' (table expected, got nil)
stack traceback:
        [C]: in function 'next'
        /opt/kumomta/share/policy-extras/queue.lua:602: in function </opt/kumomta/share/policy-extras/queue.lua:551>
```

with the changes in this commit we'll present this issue like this,
during server startup, which points a little more clearly at the setup
call and the file names parameter, and suggests more strongly that it
should be a list of strings (or config objects):

```
    runtime error: [string "./simple_policy.lua"]:52: assets/policy-extras/queue.lua:463 QueueHelperSetup: invalid value for field 'file_names'
    assets/policy-extras/queue.lua:463 Expected value of type 'list<variant<string,QueueHelperConfig>>' but got type 'string' '/opt/kumomta/etc/policy/queues.toml'
    stack traceback:
        [C]: in function 'error'
        assets/policy-extras/typing.lua:78: in method 'raise'
        assets/policy-extras/typing.lua:249: in metamethod 'newindex'
        assets/policy-extras/typing.lua:258: in function <assets/policy-extras/typing.lua:253>
        (...tail calls...)
        assets/policy-extras/queue.lua:463: in function 'policy-extras.queue.setup_with_options'
        (...tail calls...)
        [string "./simple_policy.lua"]:52: in main chunk
```

this change actually surfaced a minor issue in the ndr.lua file that is
part of an integration test, as well as in my adhoc simple_policy file.
2026-03-04 09:23:08 +00:00
Wez Furlong d1163a66f9 fix existential issue with queue helper and egress_pool in --validate mode
When running in validation mode, if a given queue block didn't specify
an egress_pool, we could hit a validation error when the validator
tried to access that missing field.

The issue is that while we can dynamically validate properties against
the underlying rust code on assignment (via newindex), we don't have
a way to validate a read (index) operation because the validator works
by creating a dummy value and serializing it.

We could probably fix this up by introducing a read validator that
tries to create an empty object and reading back its fields, but
we don't currently generate index/field getters for those rust
structs.

So for now we will allow any read of a field that isn't set
in a typed record table when it has a dynamic field validator
present.
2024-07-19 11:21:33 -07:00
Wez Furlong 426b5b8d31 log_hooks: add typing
This will perform more explicit checks to make sure that the name
is defined and so on. It also now will check for conflicting
log hook names as well.

refs: #211
2024-06-28 12:31:49 -07:00
Wez Furlong e96dfcfe38 typing: refine error handling for _dynamic fields
Better distinguish between unknown and mismatched types for dynamic
fields, and show a better error message for them.

refs: #211
2024-06-28 10:06:27 -07:00
Wez Furlong f0b91dd652 queue.lua: add typing
I regret optimizing the structure for toml when this module was
created, as it makes it difficult to define a regular schema.

This commit introduces typed records for the queue helper
data structure, and, unfortunately, a parsing layer to adapt
between the toml data and the well-defined types.

It also adjusts how lua tests are run; previously we'd co-opt the main
flow of parsing by looking at an env var, but since the modules can now
potentially require each other (especially the typing module) we need to
de-couple from that, otherwise what happens is that we'd only ever run
the typing module tests and exit. So we now have a script that imports
all the modules and runs their respective `:test()` methods.

refs: #211
2024-06-28 08:54:46 -07:00
Wez Furlong e63d1ca15c typing.lua: improve error reporting
Make the error messages a bit more regular and a bit easier
to read and trace.
2024-06-26 22:49:32 -07:00
Wez Furlong aaaa96e7fb typing.lua: improve tests 2024-06-26 17:38:34 -07:00
Wez Furlong 7392ccf3d8 typing.lua: report errors from the caller's location
Don't attribute the error to the metamethods in the typing
module, attribute them to the calling code.
2024-06-26 17:04:28 -07:00
Wez Furlong b9dccf1cc3 add policy-extras.typing lua module
The primary purpose here is to allow defining typed records
for use in our helpers.

The dkim_sign module has been updated to make use of this
to ensure that the correct shape of data has been loaded.
2024-06-26 16:38:22 -07:00