{"record":{"id":"fe6627c6d9433839","repo":"datahaven-xyz/datahaven","slug":"emptytargets","errorCode":"EmptyTargets","errorMessage":"EmptyTargets","messagePattern":"EmptyTargets","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"operator/pallets/external-validator-slashes/src/lib.rs","lineNumber":374,"sourceCode":"        #[pallet::weight(T::WeightInfo::cancel_deferred_slash(slash_indices.len() as u32))]\n        pub fn cancel_deferred_slash(\n            origin: OriginFor<T>,\n            era: EraIndex,\n            slash_indices: Vec<u32>,\n        ) -> DispatchResult {\n            ensure_root(origin)?;\n\n            let active_era = T::EraIndexProvider::active_era().index;\n\n            // We need to be in the defer period\n            ensure!(\n                era <= active_era\n                    .saturating_add(T::SlashDeferDuration::get().saturating_add(One::one()))\n                    && era > active_era,\n                Error::<T>::DeferPeriodIsOver\n            );\n\n            ensure!(!slash_indices.is_empty(), Error::<T>::EmptyTargets);\n            ensure!(\n                is_sorted_and_unique(&slash_indices),\n                Error::<T>::NotSortedAndUnique\n            );\n            // fetch slashes for the era in which we want to defer\n            let mut era_slashes = Slashes::<T>::get(era);\n\n            let last_item = slash_indices[slash_indices.len().saturating_sub(1)];\n            ensure!(\n                (last_item as usize) < era_slashes.len(),\n                Error::<T>::InvalidSlashIndex\n            );\n\n            // Remove elements starting from the highest index to avoid shifting issues.\n            for index in slash_indices.into_iter().rev() {\n                era_slashes.remove(index as usize);\n            }\n            // insert back slashes","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/datahaven-xyz/datahaven/blob/edcb13dbbcd3c29489eaa2480a6f60ee4cb1f3ec/operator/pallets/external-validator-slashes/src/lib.rs#L356-L392","documentation":"Sentinel dispatch error returned by cancel_deferred_slash when the caller supplies an empty slash_indices vector: there are no deferred slash entries to look up and cancel, so the extrinsic refuses to proceed rather than performing a no-op root call. The input at fault is the slash_indices argument, which must contain at least one valid index into the deferred slash report for the given era.","triggerScenarios":"Calling `cancel_deferred_slash(origin, era, vec![])` — typically from an off-chain automation that collected no matching slash indices, or a UI passing an unfiltered empty selection.","commonSituations":"Batch scripts canceling slashes computed by a query that returned no rows, or a governance proposal generated from stale data where all slashes were already cancelled.","solutions":["Check `slash_indices` length and skip the extrinsic call when it is empty.","Fix the off-chain query producing indices so it selects the intended deferred slashes.","If all slashes were already cancelled, treat this as a no-op instead of submitting the transaction."],"exampleFix":"// before\ncancel_deferred_slash(origin, era, indices);\n// after\nif !indices.is_empty() {\n    cancel_deferred_slash(origin, era, indices);\n}","handlingStrategy":"validation","validationCode":"if (!slashIndices.length) {\n  return; // nothing to cancel, skip transaction\n}","typeGuard":"function hasSlashIndices(indices) {\n  return Array.isArray(indices) && indices.length > 0;\n}","tryCatchPattern":"try {\n  await cancelDeferredSlash(era, indices);\n} catch (e) {\n  if (String(e).includes('EmptyTargets')) {\n    console.warn('No slashes to cancel; treating as no-op');\n  }\n}","preventionTips":["Guard automation scripts to skip the call when no indices are collected","Log the query results that produce indices for auditability","Distinguish 'already cancelled' from 'never existed' before batching"],"tags":["slashing","substrate","empty-input","validation"],"backgroundTag":"empty-required-field","analyzedSha":"edcb13dbbcd3c29489eaa2480a6f60ee4cb1f3ec","analyzedAt":"2026-09-13T19:19:32.206Z","contentChangedAt":"2026-09-13T19:19:32.206Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}