Skip to main content

sqlite_graphrag/i18n/validation/
messages_payload.rs

1//! Messages about PAYLOAD size and shape (GAP-SG-146).
2//!
3//! Body and description ceilings, empty inputs, batch line contracts, file
4//! caps and the host load guard.
5
6use crate::i18n::{current, Language};
7
8/// Localized message for `body_exceeds`.
9pub fn body_exceeds(max: usize) -> String {
10    match current() {
11        Language::English => format!("body exceeds {max} bytes"),
12        Language::Portuguese => format!("corpo excede {max} bytes"),
13    }
14}
15
16/// Localized message for `description_exceeds`.
17pub fn description_exceeds(max: usize) -> String {
18    match current() {
19        Language::English => format!("description must be <= {max} chars"),
20        Language::Portuguese => format!("descrição deve ter no máximo {max} caracteres"),
21    }
22}
23
24/// Localized message for `empty_body`.
25pub fn empty_body() -> String {
26    match current() {
27        Language::English => "body cannot be empty: provide --body, --body-file, or --body-stdin with content, or supply a graph via --entities-file/--graph-stdin".to_string(),
28        Language::Portuguese => "o corpo não pode estar vazio: forneça --body, --body-file ou --body-stdin com conteúdo, ou um grafo via --entities-file/--graph-stdin".to_string(),
29    }
30}
31
32/// Localized message for `empty_query`.
33pub fn empty_query() -> String {
34    match current() {
35        Language::English => "query cannot be empty".to_string(),
36        Language::Portuguese => "a consulta não pode estar vazia".to_string(),
37    }
38}
39
40/// File bytes are not valid UTF-8.
41pub fn file_not_utf8(err: &impl std::fmt::Display) -> String {
42    match current() {
43        Language::English => format!("file is not valid UTF-8: {err}"),
44        Language::Portuguese => format!("arquivo não é UTF-8 válido: {err}"),
45    }
46}
47
48/// Invalid memory source string.
49pub fn invalid_memory_source(other: &str, expected: &str) -> String {
50    match current() {
51        Language::English => {
52            format!("invalid memory source: {other}; expected one of {expected}")
53        }
54        Language::Portuguese => {
55            format!("fonte de memória inválida: {other}; esperado um de {expected}")
56        }
57    }
58}
59
60/// `--max-files` cap exceeded (generic form used by ingest-claude/codex).
61pub fn max_files_exceeded(found: usize, max: usize) -> String {
62    match current() {
63        Language::English => {
64            format!("found {found} files, exceeds --max-files cap of {max}")
65        }
66        Language::Portuguese => {
67            format!("encontrados {found} arquivos, excede o limite --max-files de {max}")
68        }
69    }
70}
71
72/// `--max-files` cap exceeded with all-or-nothing abort (ingest-opencode).
73pub fn max_files_exceeded_all_or_nothing(found: usize, max: usize) -> String {
74    match current() {
75        Language::English => format!(
76            "found {found} files exceeding --max-files cap of {max}; aborting (all-or-nothing)"
77        ),
78        Language::Portuguese => format!(
79            "encontrados {found} arquivos excedendo o limite --max-files de {max}; \
80             abortando (tudo-ou-nada)"
81        ),
82    }
83}
84
85/// `--max-files` cap exceeded with pattern-matching wording (ingest).
86pub fn max_files_exceeded_matching(found: usize, max: usize) -> String {
87    match current() {
88        Language::English => format!(
89            "found {found} files matching pattern, exceeds --max-files cap of {max} \
90             (raise the cap or narrow the pattern)"
91        ),
92        Language::Portuguese => format!(
93            "encontrados {found} arquivos no padrão, excede o limite --max-files de {max} \
94             (aumente o limite ou restrinja o padrão)"
95        ),
96    }
97}
98
99/// Batch line: invalid JSON.
100pub fn batch_line_invalid_json(index: usize, err: &impl std::fmt::Display) -> String {
101    match current() {
102        Language::English => format!("line {index}: invalid JSON: {err}"),
103        Language::Portuguese => format!("linha {index}: JSON inválido: {err}"),
104    }
105}
106
107/// Batch line: name normalizes empty.
108pub fn batch_line_name_empty(index: usize) -> String {
109    match current() {
110        Language::English => format!("line {index}: name normalizes to empty string"),
111        Language::Portuguese => {
112            format!("linha {index}: nome normaliza para string vazia")
113        }
114    }
115}
116
117/// Batch line: type/description required.
118pub fn batch_line_type_description_required(index: usize) -> String {
119    match current() {
120        Language::English => format!(
121            "line {index}: --type and --description are required when creating a new memory"
122        ),
123        Language::Portuguese => format!(
124            "linha {index}: --type e --description são obrigatórios ao criar uma nova memória"
125        ),
126    }
127}
128
129/// Ingest aborted on first failure (`--fail-fast` / default all-or-nothing path).
130pub fn ingest_aborted_on_first_failure(err: &impl std::fmt::Display) -> String {
131    match current() {
132        Language::English => format!("ingest aborted on first failure: {err}"),
133        Language::Portuguese => format!("ingest abortado na primeira falha: {err}"),
134    }
135}
136
137/// System load average exceeds 2× ncpus.
138pub fn system_load_exceeded(load: f64, ncpus: usize) -> String {
139    match current() {
140        Language::English => format!(
141            "system load average {load:.2} exceeds 2x ncpus ({ncpus}); \
142             pass --no-max-load-check to override (not recommended)"
143        ),
144        Language::Portuguese => format!(
145            "carga média do sistema {load:.2} excede 2x ncpus ({ncpus}); \
146             passe --no-max-load-check para sobrescrever (não recomendado)"
147        ),
148    }
149}