packages/sql-semantics-mysql/src/Model/Diagnostic/SemanticException.php

1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\MySql\Model\Diagnostic;
6
7use RuntimeException;
8use SqlSemantics\Platform\MySql\Model\Statement\Fact\Diagnostic;
9
10/**
11 * Semantic problems established while analyzing grammatical SQL.
12 *
13 * @visibility public
14 * @example Rejecting a query that names a missing relation
15 *     (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT * FROM t', []) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\SemanticException
16 */
17final class SemanticException extends RuntimeException implements \SqlSemantics\AnalysisException
18{
19    /**
20     * @param non-empty-list<Diagnostic> $diagnostics The problems in derivation order
21     */
22    public function __construct(public readonly array $diagnostics)
23    {
24        parent::__construct(implode("\n", array_map(static fn (Diagnostic $diagnostic): string => $diagnostic->message(), $diagnostics)));
25    }
26}
27