{"record":{"id":"c9f1e325359c60fa","repo":"RyanCodrai/turbovec","slug":"turbovec-warning-message","errorCode":null,"errorMessage":"turbovec: warning: {message}","messagePattern":"turbovec: warning: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"turbovec/src/warning.rs","lineNumber":67,"sourceCode":"///\n/// ```\n/// fn to_my_log(message: &str) {\n///     eprintln!(\"[turbovec] {message}\");\n/// }\n/// turbovec::set_warning_hook(Some(to_my_log));\n/// turbovec::set_warning_hook(None); // back to the default\n/// ```\npub fn set_warning_hook(hook: Option<WarningHook>) {\n    let ptr = match hook {\n        Some(f) => f as *const () as *mut (),\n        None => std::ptr::null_mut(),\n    };\n    HOOK.store(ptr, Ordering::Release);\n}\n\n/// Deliver `message` to the installed hook, or to stderr if there is\n/// none.\npub(crate) fn warn(message: &str) {\n    let ptr = HOOK.load(Ordering::Acquire);\n    if ptr.is_null() {\n        eprintln!(\"turbovec: warning: {message}\");\n        return;\n    }\n    // SAFETY: `HOOK` is only ever written by `set_warning_hook`, which\n    // stores either null (handled above) or a `WarningHook` cast to\n    // `*mut ()`. Function and data pointers are the same width on every\n    // target this crate compiles for (64-bit only, enforced in lib.rs),\n    // so the round trip recovers exactly the pointer that was stored.\n    let hook: WarningHook = unsafe { std::mem::transmute::<*mut (), WarningHook>(ptr) };\n    hook(message);\n}\n","sourceCodeStart":49,"sourceCodeEnd":81,"githubUrl":"https://github.com/RyanCodrai/turbovec/blob/ccab9f325e6ce2a270a87daf01ae4e443bcf2d49/turbovec/src/warning.rs#L49-L81","documentation":"This is turbovec's internal warning output, emitted by the `warn` function when the library needs to surface a non-fatal issue to the caller. It is not a panic or returned error: the message goes to stderr (or to a user-installed warning hook if one was registered via `set_warning_hook`). The library uses it to report conditions it recovers from but that the caller should know about.","triggerScenarios":"Any call into turbovec internals that calls `warn(message)` when no warning hook is installed — e.g. a function detects a degraded/ignored input, a fallback path is taken, or a questionable configuration is encountered. The literal stderr line 'turbovec: warning: {message}' is printed only when the HOOK static is null.","commonSituations":"Running an application where turbovec logs warnings to stderr during bulk operations; CI logs polluted with 'turbovec: warning:' lines; developers unaware they can redirect these messages by installing a custom hook via `set_warning_hook` instead of letting them hit stderr.","solutions":["Read the trailing `{message}` text to identify the actual condition being reported","Install a warning hook with `set_warning_hook` to capture warnings programmatically (logging, metrics, tests) instead of stderr","Fix the underlying condition described in the message (invalid input, fallback taken, etc.)","In tests, install a hook that asserts/collects warnings so they do not clutter test output"],"exampleFix":"// before: warnings go to stderr, easy to miss\nlet v = turbovec::do_thing(&input);\n\n// after: capture warnings programmatically\nturbovec::set_warning_hook(Some(Box::new(|msg| {\n    log::warn!(\"turbovec: {}\", msg);\n})));\nlet v = turbovec::do_thing(&input);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install a warning hook early (at program start) so all turbovec warnings are captured and actionable","Monitor stderr for lines prefixed with 'turbovec: warning:' in CI and fail or alert on them","Read and fix the specific condition in each warning message rather than suppressing output","Treat repeated warnings as signals of data or configuration problems, not noise"],"tags":["rust","logging","stderr","diagnostics"],"backgroundTag":"deprecated-api-usage","analyzedSha":"ccab9f325e6ce2a270a87daf01ae4e443bcf2d49","analyzedAt":"2026-09-06T08:39:18.516Z","contentChangedAt":"2026-09-06T08:39:18.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}