{"record":{"id":"dafa4dd3c319665f","repo":"tonhowtf/omniget","slug":"escreva-o-texto-da-marca-d-gua","errorCode":null,"errorMessage":"escreva o texto da marca d'água","messagePattern":"escreva o texto da marca d'água","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf_write.rs","lineNumber":351,"sourceCode":"                .ok()\n                .and_then(|(_, ids)| ids.first().copied());\n            match inherited {\n                Some(id) => Some(id),\n                None => {\n                    let id = doc.add_object(Object::Dictionary(dictionary! {}));\n                    if let Ok(page) = doc.get_dictionary_mut(page_id) {\n                        page.set(\"Resources\", Object::Reference(id));\n                    }\n                    Some(id)\n                }\n            }\n        }\n    }\n}\n\nfn watermark_one(opts: &WatermarkOptions, input: &str) -> anyhow::Result<WriteItem> {\n    if opts.text.trim().is_empty() && opts.mode != \"bates\" {\n        return Err(anyhow!(\"escreva o texto da marca d'água\"));\n    }\n    let mut doc = load(input, \"\")?;\n    let pages = doc.get_pages();\n    let font_id = doc.add_object(dictionary! {\n        \"Type\" => \"Font\",\n        \"Subtype\" => \"Type1\",\n        \"BaseFont\" => \"Helvetica\",\n    });\n    let alpha = (opts.opacity.min(100) as f32) / 100.0;\n    let gs_id = doc.add_object(dictionary! {\n        \"Type\" => \"ExtGState\",\n        \"ca\" => alpha,\n        \"CA\" => alpha,\n    });\n    let gray = (opts.gray.min(100) as f32) / 100.0;\n\n    let ids: Vec<(u32, lopdf::ObjectId)> = pages.iter().map(|(n, id)| (*n, *id)).collect();\n    for (index, (_, page_id)) in ids.iter().enumerate() {","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf_write.rs#L333-L369","documentation":"watermark_one stamps text onto every page; if opts.text is blank (after trim) and mode is not \"bates\", there is nothing to draw, so it returns 'escreva o texto da marca d'água'. Bates numbering supplies its own digits, so it is exempt.","triggerScenarios":"Calling watermark with mode != \"bates\" and WatermarkOptions::text empty or whitespace-only.","commonSituations":"User leaves the watermark text field blank in a UI; caller passes Default::default() options; text lost in config deserialization; using \"bates\" intent but forgetting to set mode=\"bates\".","solutions":["Provide non-empty opts.text for normal watermark modes","Use mode=\"bates\" if the intent is sequential Bates numbering instead of a text stamp","Validate text.trim().is_empty() in the caller before invoking"],"exampleFix":"// before\nwatermark_one(&WatermarkOptions { text: \"\".into(), ..Default::default() }, input)?;\n// after\nlet text = \"CONFIDENCIAL\";\nassert!(!text.trim().is_empty(), \"texto da marca d'água obrigatório\");\nwatermark_one(&WatermarkOptions { text: text.into(), ..Default::default() }, input)?;","handlingStrategy":"validation","validationCode":"if opts.mode != \"bates\" && opts.text.trim().is_empty() {\n    anyhow::bail!(\"informe o texto da marca d'água ou use o modo bates\");\n}","typeGuard":"fn watermark_text_ok(opts: &WatermarkOptions) -> bool {\n    opts.mode == \"bates\" || !opts.text.trim().is_empty()\n}","tryCatchPattern":"match watermark_one(&opts, input) {\n    Ok(item) => item,\n    Err(e) if e.to_string().contains(\"marca d'água\") => {\n        eprintln!(\"texto da marca d'água é obrigatório\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Mark the watermark text field as required in UIs unless Bates mode is selected","Trim and validate text before passing options","Default to mode=\"bates\" when no text is supplied"],"tags":["pdf","validation","watermark","missing-argument"],"backgroundTag":"empty-required-field","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}