[Canonical page](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/match-error/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# MatchError

The error returned by [`slots`](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/slots.md>) of the `plen-assign` crate. It reports either an invalid item in the pool or the requirements, or a project state that doesn't allow building slots. It converts into the core [`Error`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/error.md>), so `?` works in functions that return `plen_core::Error`.

## Declaration

```rust
#[derive(Clone, Debug, PartialEq)]
pub enum MatchError {
    Invalid { path: String, message: String },
    Project(ProjectError),
}

impl std::error::Error for MatchError {}
impl std::fmt::Display for MatchError {}
impl From<MatchError> for plen_core::Error {}
```

## Variants

| Variant | When it occurs |
|---|---|
| `Invalid { path, message }` | An item of the pool or a requirement is invalid. `path` names the item, for example `requirements[2].assignments[0]`; `message` says what's wrong with it. |
| `Project(ProjectError)` | The project has no accepted baseline: it's unsolved, or it has unsolved edits after [`apply`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/project/project.md#apply>). The wrapped value is [`ProjectError::NoBaseline`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/project-error.md>). |

### `Invalid` paths

| Path | When it occurs |
|---|---|
| `pool.workers[i].resource` | Unknown resource, or the same resource listed as two workers |
| `pool.workers[i].skills[j].id` | The same skill listed twice on one worker |
| `pool.workers[i].skills[j].value` | Not finite |
| `requirements[i].id` | Duplicate requirement id, or one of its slot ids is an active assignment on another task |
| `requirements[i].task` | Unknown or unscheduled task |
| `requirements[i].count` | `0` |
| `requirements[i].units` | Not finite, or `<= 0` |
| `requirements[i].matches[j].value` | Not finite |
| `requirements[i].assignments` | More entries than `count`, or an assignment with one of this requirement's slot ids is left out of the list |
| `requirements[i].assignments[k]` | Unknown or inactive assignment, an assignment on another task, or an assignment bound twice |

## Display

| Variant | Output |
|---|---|
| `Invalid` | `"{path}: {message}"` |
| `Project` | The [`ProjectError`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/project-error.md>) text, for example `no-baseline` |

## Conversion to `Error`

| `MatchError` | `plen_core::Error` |
|---|---|
| `Invalid { path, message }` | [`Error::Input`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/error.md>): an [`InputError`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/input-error.md>) of kind `Validation`, with `path: Some(path)` and the same `message` |
| `Project(e)` | `Error::Project(e)` |

## Example

```rust
use plen_assign::{slots, MatchError, Pool};
use plen_core::{Project, ProjectError};

fn main() {
    let project = Project::default(); // never solved

    match slots(&project, &Pool::default(), &[]) {
        Ok(slots) => println!("{} slots", slots.len()),
        Err(MatchError::Project(ProjectError::NoBaseline)) => println!("solve the project first"),
        Err(MatchError::Project(e)) => println!("project error: {e}"),
        Err(MatchError::Invalid { path, message }) => println!("{path}: {message}"),
    }
}
```

## Related

- [`slots`](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/slots.md>) - the function that returns this error
- [`Error`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/error.md>) - the core error a `MatchError` converts into with `?`
- [`ProjectError`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/project-error.md>) - the type wrapped by the `Project` variant
- [Error handling](<https://docs.dhtmlx.com/planning-engine/rust/error-handling.md>) - shows how to match `MatchError` from the skill layer
- [Skills and Requirements](<https://docs.dhtmlx.com/planning-engine/rust/resources-and-assignment/skills-and-requirements.md>) - lists the skill-layer errors in the full workflow
