Skip to main content

qt_build_utils/
error.rs

1// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2// SPDX-FileContributor: Andrew Hayzen <andrew.hayzen@kdab.com>
3//
4// SPDX-License-Identifier: MIT OR Apache-2.0
5
6use thiserror::Error;
7
8#[derive(Error, Debug)]
9/// Errors that can occur while using [crate::QtBuild]
10pub enum QtBuildError {
11    /// `QMAKE` environment variable was set but Qt was not detected
12    #[error("QMAKE environment variable specified as {qmake_env_var} but could not detect Qt: {error:?}")]
13    QMakeSetQtMissing {
14        /// The value of the qmake environment variable when the error occurred
15        qmake_env_var: String,
16        /// The inner error that occurred
17        error: Box<anyhow::Error>,
18    },
19    /// Qt was not found
20    #[error("Could not find Qt")]
21    QtMissing,
22    /// Qt was not found within the version requirements
23    #[error("Could not find matching Qt install for requested version(s): {1} from available local version(s): {0}", .available_versions.iter().map(|version| version.to_string()).collect::<Vec<_>>().join(", "), .requested_versions.iter().map(|version| version.to_string()).collect::<Vec<_>>().join(", "))]
24    QtMissingVersion {
25        /// The Qt versions found locally
26        available_versions: Vec<semver::Version>,
27        /// The Qt versions requested
28        requested_versions: Vec<semver::Version>,
29    },
30    /// Executing `qmake -query` failed
31    #[error("Executing `qmake -query` failed: {0:?}")]
32    QmakeFailed(#[from] std::io::Error),
33    /// `QT_VERSION_MAJOR` environment variable was specified but could not be parsed as an integer
34    #[error("QT_VERSION_MAJOR environment variable specified as {qt_version_major_env_var} but could not parse as integer: {source:?}")]
35    QtVersionMajorInvalid {
36        /// The Qt major version from `QT_VERSION_MAJOR`
37        qt_version_major_env_var: String,
38        /// The [std::num::ParseIntError] when parsing the `QT_VERSION_MAJOR`
39        source: std::num::ParseIntError,
40    },
41    /// `QT_VERSION_MAJOR` environment variable was specified but the Qt version specified by `qmake -query QT_VERSION` did not match
42    #[error("qmake version ({qmake_version}) does not match version specified by QT_VERSION_MAJOR ({qt_version_major})")]
43    QtVersionMajorDoesNotMatch {
44        /// The qmake version
45        qmake_version: u64,
46        /// The Qt major version from `QT_VERSION_MAJOR`
47        qt_version_major: u64,
48    },
49}