fix(config): reject channel properties of the wrong type

- ptree::get(key, default) returns the default also for a value that
  does not convert, so a typo (e.g. sndBufSize=big) silently gave the
  default value
- Use the default only for a missing key; throw ParserError with the
  key and the value for a value of the wrong type
- Rethrow parser errors in the config plugin: before, the device
  logged the error and continued without its channel configuration
- Enable JSONParser and SuboptParser RejectsValuesOfTheWrongType
- Update the documentation pages that described the defect, and
  the source line links into the changed files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-04 20:31:06 +00:00
committed by Dennis Klein
parent 442b203d0d
commit b70595cebe
9 changed files with 73 additions and 55 deletions

View File

@@ -107,7 +107,7 @@ The configuration of a sub-channel is a group of properties with the keys `chans
## The config plugin
The config plugin is a part of each device made with `runDevice.h`. It declares the options of the groups Device and Shared memory in the [table of options](/reference/options/), and reads the channel configuration ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L25-L53)).
The config plugin is a part of each device made with `runDevice.h`. It declares the options of the groups Device and Shared memory in the [table of options](/reference/options/), and reads the channel configuration ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L25-L54)).
When the device goes into the state `INITIALIZING DEVICE`, the config plugin:
@@ -115,7 +115,7 @@ When the device goes into the state `INITIALIZING DEVICE`, the config plugin:
2. Reads the JSON file of `--mq-config` for this value. If there is no `--mq-config`, it reads `--channel-config`.
3. Stores the channel properties with `SetProperties()`.
If the parser throws an exception, the plugin logs the message with the severity `error`, and the device continues without these channels. If `--id` and `--config-key` are empty, the plugin logs a warning and reads nothing. [JSON configuration](/reference/json/#errors) lists the errors.
If the parser throws an exception, the plugin logs the message with the severity `error` and throws the exception again. The device goes to `ERROR` and does not start. If `--id` and `--config-key` are empty, the plugin logs a warning and reads nothing. [JSON configuration](/reference/json/#errors) lists the errors.
The device runner makes the plugins of `-P` before the config plugin. In `INITIALIZING DEVICE`, their callbacks thus run first. The config plugin then replaces the values of all channel properties that the configuration also gives.

View File

@@ -40,7 +40,7 @@ The file has one entry for each device in `fairMQOptions.devices`. This is the e
A device uses the entry whose `id` is equal to its `--id`. With `--config-key processor`, the device uses
the entry with `"key": "processor"` instead ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L29-L33),
[JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L69)). Thus `processor1` and `processor2` have different
[JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L90)). Thus `processor1` and `processor2` have different
IDs, but the same channels. The [JSON configuration](/reference/json/) page describes the format.
## Build the example

View File

@@ -255,9 +255,9 @@ The test `Config.SetConfig` parses two options and gives the object to the devic
### The device options and the channels
The device options, for example `--id`, `--transport`, `--session`, `--mq-config` and `--channel-config`, are the
options of the config plugin ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L56-L87)). In
options of the config plugin ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L57-L88)). In
`INITIALIZING DEVICE`, the config plugin also turns `--mq-config` or `--channel-config` into channel properties
([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L22-L53)). A program without `DeviceRunner` has two ways to get
([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L22-L54)). A program without `DeviceRunner` has two ways to get
them:
- Load the config plugin with a plugin manager, and add its options before the parse. See

View File

@@ -24,7 +24,7 @@ The keys are case-sensitive. The `--channel-config` parser logs a warning for an
## All properties
The type is the C++ type of the property. The parsers of `--channel-config` and of JSON files convert the values to this type. A value that the parser cannot convert gives the default, without a message ([_jsonparser.cxx](https://github.com/FairRootGroup/FairMQ/blob/dev/test/properties/_jsonparser.cxx#L157-L161)).
The type is the C++ type of the property. The parsers of `--channel-config` and of JSON files convert the values to this type. For a value that it cannot convert, the parser throws `fair::mq::ParserError` ([_jsonparser.cxx](https://github.com/FairRootGroup/FairMQ/blob/dev/test/properties/_jsonparser.cxx#L158-L166)). A missing key gives the default.
| Key | Type | Default | Allowed values | Effect |
| --- | --- | --- | --- | --- |
@@ -44,15 +44,15 @@ The type is the C++ type of the property. The parsers of `--channel-config` and
| [`portRangeMin`](#portrangemin-portrangemax-and-autobind) | int | [`22000`](/source/fairmq/Channel.h/#L380) | A TCP port | Lowest port for autobind. |
| [`portRangeMax`](#portrangemin-portrangemax-and-autobind) | int | [`23000`](/source/fairmq/Channel.h/#L381) | A TCP port | Highest port for autobind. |
| [`autoBind`](#portrangemin-portrangemax-and-autobind) | bool | [`true`](/source/fairmq/Channel.h/#L382-L386) | `true`, `false`, `1`, `0` | Bind to a random port of the range when the bind fails. |
| [`numSockets`](#numsockets) | int | [`0`](/source/fairmq/JSONParser.cxx/#L108) | 0 or more | Number of sub-channels with the same properties. |
| [`numSockets`](#numsockets) | int | [`0`](/source/fairmq/JSONParser.cxx/#L129) | 0 or more | Number of sub-channels with the same properties. |
The JSON parser uses the same defaults ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L90-L105)). The device also uses them for a property that is not set ([Channel.cxx](/source/fairmq/Channel.cxx/#L92-L112)).
The JSON parser uses the same defaults ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L111-L126)). The device also uses them for a property that is not set ([Channel.cxx](/source/fairmq/Channel.cxx/#L92-L112)).
## The properties in detail
### `name`
The name of the channel. In `--channel-config`, write `name=data`, or put the name and a colon before the first key: `data:type=push,...` ([SuboptParser.cxx](/source/fairmq/SuboptParser.cxx/#L91-L98)). Each channel must have a name. Without it, the parsers of JSON files and of `--channel-config` throw `boost::property_tree::ptree_bad_path` ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L107)). The `--channel-config` parser first logs `missing channel name in argument of option --channel-config`. The config plugin logs the exception, and the device gets no channels from this configuration. In the property key, the name is the `<name>` part of `chans.<name>.<index>.<key>`.
The name of the channel. In `--channel-config`, write `name=data`, or put the name and a colon before the first key: `data:type=push,...` ([SuboptParser.cxx](/source/fairmq/SuboptParser.cxx/#L91-L98)). Each channel must have a name. Without it, the parsers of JSON files and of `--channel-config` throw `boost::property_tree::ptree_bad_path` ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L128)). The `--channel-config` parser first logs `missing channel name in argument of option --channel-config`. The config plugin logs the exception and throws it again, and the device goes to `ERROR`. In the property key, the name is the `<name>` part of `chans.<name>.<index>.<key>`.
A sub-channel has the name `<name>[<index>]`, for example `data[0]`. Before the device attaches a sub-channel, [`Channel::Validate()`](/api/fair/mq/Channel/#Validate) checks this full name ([Channel.cxx](/source/fairmq/Channel.cxx/#L183-L190)). The allowed characters are `a`–`z`, `A`–`Z`, `0`–`9`, `-`, `_`, `[`, `]` and `#`. For another character, the device logs `channel name contains illegal character` and does not attach the sub-channel. The device then goes to `ERROR`: at once for a binding sub-channel, after the time of `--init-timeout` for a connecting sub-channel ([Device.cxx](/source/fairmq/Device.cxx/#L217-L265)).
@@ -176,7 +176,7 @@ If the configured port is in use, autobind binds to a random port. The device lo
### `numSockets`
Only in `--channel-config` and on the channel level of a JSON file. For a value above 0, the parser makes this number of sub-channels, all with the properties of the channel ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L108-L122)).
Only in `--channel-config` and on the channel level of a JSON file. For a value above 0, the parser makes this number of sub-channels, all with the properties of the channel ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L129-L143)).
- In JSON, the parser ignores the `sockets` array of the channel. All sub-channels get the `address` of the channel.
- In `--channel-config`, the parser ignores the `address=` keys. The sub-channels have no address.

View File

@@ -18,7 +18,7 @@ The file of the [1-n-1 example](/examples/1-n-1/) has three entries: one for the
## Structure
The parser reads this tree ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L39-L190)):
The parser reads this tree ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L39-L211)):
```txt
fairMQOptions object, required
@@ -63,10 +63,10 @@ An entry needs `id` or `key`, otherwise no device can select it.
## How the device finds its entry
The [config plugin](/concepts/configuration/#the-config-plugin) reads the file when the device goes into the state `INITIALIZING DEVICE` ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L25-L53)):
The [config plugin](/concepts/configuration/#the-config-plugin) reads the file when the device goes into the state `INITIALIZING DEVICE` ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L25-L54)):
1. The plugin takes the value of `--config-key`. Without `--config-key`, it takes the value of `--id`.
2. The parser compares this value with the `key` of each device entry. For an entry without `key`, it compares the value with `id` ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L69-L74)).
2. The parser compares this value with the `key` of each device entry. For an entry without `key`, it compares the value with `id` ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L90-L95)).
3. The parser reads the channels of each entry that matches.
An entry with a `key` does not match its `id`. Several devices can use the same entry. In the start script of the 1-n-1 example, both processors have their own ID and the same key `processor`:
@@ -96,15 +96,13 @@ The entry with the ID `other` has the key `sink`. `--config-key sink` selects it
## `numSockets`
With `numSockets` above 0, the parser makes this number of sub-channels. All of them get the values of the channel, also the `address`. The parser then ignores the `sockets` array ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L108-L122)). [Channel properties](/reference/channel-properties/#numsockets) describes the effect on binding sub-channels.
With `numSockets` above 0, the parser makes this number of sub-channels. All of them get the values of the channel, also the `address`. The parser then ignores the `sockets` array ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L129-L143)). [Channel properties](/reference/channel-properties/#numsockets) describes the effect on binding sub-channels.
## Value types
Write strings as JSON strings, numbers as JSON numbers, and booleans as `true` or `false`. [Channel properties](/reference/channel-properties/) gives the type of each property.
:::caution[Wrong types]
The parser reads each value with a default ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L90-L105)). If it cannot convert a value, it uses the default and shows no error. For example, `"sndBufSize": "big"` gives `sndBufSize` 1000. To see the values, start the device with `--severity trace`: the parser then logs each property of each sub-channel.
:::
The parser uses the default of a property only when the key is missing ([JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L111-L126)). If it cannot convert a value, it throws [`fair::mq::ParserError`](/api/fair/mq/ParserError/). For example, `"sndBufSize": "big"` gives `Invalid value 'big' for channel property 'sndBufSize'`. To see the values, start the device with `--severity trace`: the parser then logs each property of each sub-channel.
## Errors
@@ -115,12 +113,12 @@ The parser reads each value with a default ([JSONParser.cxx](/source/fairmq/JSON
| A channel has no `name`. | `boost::property_tree::ptree_bad_path` |
| The ID is empty. This occurs only when you call the parser from code. | [`fair::mq::ParserError`](/api/fair/mq/ParserError/): ``no device ID provided. Provide with `--id` cmd option`` |
| No entry matches the ID or the key. | No error. The device has no channels from the file. |
| A value has the wrong type. | No error. The parser uses the default. |
| A value has the wrong type. | [`fair::mq::ParserError`](/api/fair/mq/ParserError/): `Invalid value '<value>' for channel property '<key>'` |
The config plugin catches the exceptions and logs their message with the severity `error` ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L46-L48)). The device then continues without the channels of the file. If the device has no `--id` and no `--config-key`, the plugin logs the warning `No device ID or config-key provided for the configuration parser.` and does not read the file.
The config plugin catches the exceptions, logs `Invalid channel configuration:` and the message with the severity `error`, and throws the exception again ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L46-L49)). The device then goes to `ERROR` in `INITIALIZING DEVICE` and does not start. If the device has no `--id` and no `--config-key`, the plugin logs the warning `No device ID or config-key provided for the configuration parser.` and does not read the file.
:::caution
A device with a broken file can start without channels. If your device does not find a channel, look for an error message from the parser at the start of the log.
:::tip
If your device does not start, look for `Invalid channel configuration:` at the start of the log.
:::
## Parse a file from code