qubit_batch/process/batch_process_result_build_error.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10use thiserror::Error;
11
12/// Error returned when constructing a batch process result with invalid counters.
13///
14/// ```rust
15/// use qubit_batch::{
16/// BatchProcessResultBuildError,
17/// BatchProcessResultBuilder,
18/// };
19///
20/// let error = BatchProcessResultBuilder::builder(1)
21/// .completed_count(2)
22/// .processed_count(2)
23/// .chunk_count(1)
24/// .build()
25/// .expect_err("completed count should not exceed declared item count");
26///
27/// assert!(matches!(
28/// error,
29/// BatchProcessResultBuildError::CompletedCountExceeded { .. }
30/// ));
31/// ```
32#[derive(Debug, Clone, Error, PartialEq, Eq)]
33pub enum BatchProcessResultBuildError {
34 /// The completed item count is greater than the declared item count.
35 #[error(
36 "completed item count must not exceed declared item count: item_count {item_count}, completed_count {completed_count}"
37 )]
38 CompletedCountExceeded {
39 /// Declared item count.
40 item_count: usize,
41 /// Number of completed items.
42 completed_count: usize,
43 },
44
45 /// The processed item count is greater than the completed item count.
46 #[error(
47 "processed item count must not exceed completed item count: completed_count {completed_count}, processed_count {processed_count}"
48 )]
49 ProcessedCountExceeded {
50 /// Number of completed items.
51 completed_count: usize,
52 /// Number of successfully processed items.
53 processed_count: usize,
54 },
55
56 /// Completed items require at least one submitted chunk.
57 #[error("chunk count must be positive when items completed: completed_count {completed_count}")]
58 MissingChunkForCompletedItems {
59 /// Number of completed items.
60 completed_count: usize,
61 },
62
63 /// The submitted chunk count is greater than the completed item count.
64 #[error(
65 "chunk count must not exceed completed item count: completed_count {completed_count}, chunk_count {chunk_count}"
66 )]
67 ChunkCountExceeded {
68 /// Number of completed items.
69 completed_count: usize,
70 /// Number of submitted chunks.
71 chunk_count: usize,
72 },
73}