Docs/Numerics
Error Taxonomy
Fallible operations return Result<T, E> with an explicit error type. Library code still holds panic sites outside tests: 30 .unwrap(), 48 .expect( (plus 28 in the fnp-conformance harness), 20 unreachable! and 1 panic! (the allocation-error hook, raised as MemoryError) (2026-10-08 count; comments, strings, #[cfg(test)] items and src/bin excluded). The 2026-09-24 census in docs/planning/audit_numpy_mocks.md §D classifies the sites of that date. None panics from a single-threaded call; the sort/argsort/unique/searchsorted comparators that panicked when another thread wrote a NaN into the operand mid-call now order NaN last instead (bead deadlock-audit-rc0923-epic-71qy3.20). The exact error variants per crate (verified against crates/fnp-*/src/lib.rs):
| Crate | Error type | Variants |
|---|---|---|
fnp-ndarray |
ShapeError |
InvalidItemSize, InvalidDimension(isize), MultipleUnknownDimensions, Overflow, RankMismatch { expected, actual }, InvalidWindowDimension { axis, window, dim }, OutOfBoundsView { required_nbytes, available_nbytes }, IncompatibleBroadcast { lhs, rhs }, IncompatibleElementCount { old, new } |
fnp-dtype |
StorageError |
IndexOutOfBounds { index, len }, UnsupportedCast { from, to }, StructuredFieldMismatch { expected, got } |
fnp-iter |
TransferError |
SelectorInvalidContext(&'static str), OverlapPolicyTriggered(&'static str), WhereMaskContractViolation(&'static str), SameValueCastRejected, StringWidthMismatch(&'static str), SubarrayBroadcastContractViolation(&'static str), FlatiterReadViolation(&'static str), FlatiterWriteViolation(&'static str), NditerOverlapPolicy(&'static str), FpeCastError(&'static str) |
fnp-iter |
FlatIterContractError |
IndexingViolation(&'static str) |
fnp-iter |
NditerError |
InvalidConfiguration(&'static str), MultiIndexViolation(&'static str), NoBroadcastViolation(&'static str), OverlapPolicyTriggered(&'static str), NdindexShapeValidation(&'static str), PythonBridgeFailure(String) |
fnp-ufunc |
UFuncError |
Shape(ShapeError), InvalidInputLength { expected, actual }, AxisOutOfBounds { axis, ndim }, EmptyReduction { op }, FloatingPoint { kind, detail }, SignatureConflict { sig, signature }, SignatureParse { detail }, FixedSignatureInvalid { detail }, OverridePrecedenceViolation { detail }, DispatchResolutionFailed { detail }, TypeResolutionInvalid { detail }, ReductionContractViolation { detail }, LoopRegistryInvalid { detail }, PolicyUnknownMetadata { detail }, Msg(String) (catch-all for one-off parameter errors) |
fnp-ufunc (masked) |
MAError |
MaskShapeMismatch { data_shape, mask_shape }, UFunc(UFuncError) (auto-wraps via From), Msg(String) |
fnp-linalg |
LinAlgError |
ShapeContractViolation(&'static str), SolverSingularity, CholeskyContractViolation(&'static str), QrModeInvalid, SvdNonConvergence, SpectralConvergenceFailed, LstsqTupleContractViolation(&'static str), NormDetRankPolicyViolation(&'static str), BackendBridgeInvalid(&'static str), PolicyUnknownMetadata(&'static str) |
fnp-random |
RandomError |
InvalidUpperBound, InvalidParameter |
fnp-random |
SeedSequenceError |
GenerateStateContractViolation, SpawnContractViolation |
fnp-random |
BitGeneratorError |
GeneratorBindingInvalid(&'static str), InitFailed(&'static str), SpawnContractViolation(&'static str), JumpContractViolation(&'static str), StateSchemaInvalid(&'static str), PickleStateMismatch(&'static str) |
fnp-random |
RngConstructorError |
SeedMetadataInvalid |
fnp-random |
RandomPolicyError |
UnknownMetadata |
fnp-io |
IOError |
MagicInvalid, HeaderSchemaInvalid(&'static str), DTypeDescriptorInvalid, WriteContractViolation(&'static str), ReadPayloadIncomplete(&'static str), PicklePolicyViolation, MemmapContractViolation(&'static str), LoadDispatchInvalid(&'static str), NpzArchiveContractViolation(&'static str), PolicyUnknownMetadata(&'static str) |
fnp-runtime |
(return values, not a single enum) | DecisionAction::FailClosed is the rejection signal; the rejection reason travels alongside it on the enclosing DecisionEvent via reason_code: String. OverrideAuditEvent records explicit human bypass requests. |
Four design points:
- Each crate uses a
reason_code()method on its error type (where applicable) that returns a stable&'static strslug:linalg_solver_singularity,io_pickle_policy_violation,transfer_nditer_overlap_policy, etc. The runtime evidence ledger and external monitoring systems use these to alert on specific failure modes without parsing display messages. &'static strdetail messages are the dominant carrier for context. The variant tells you the error category, the static string tells you the specific contract that was violated. The string is stable across patches and safe to assert against in tests.UFuncError::Msg(String)is the catch-all for one-off parameter errors (off-by-one ranges, malformed kwargs) that don't yet have a dedicated structured variant. Most failures hit a structured variant; only the long tail of unstructured user-input checks lands inMsg. Callers should matchErr(UFuncError::Shape(_))first, then the other structured variants, thenMsglast.- Error types compose through
Fromimpls. AShapeErrorfrom SCE flows up intoUFuncError::Shape(...)automatically. AUFuncErrorfrom a ufunc call flows up intoMAError::UFunc(...)for masked-array operations. You don't need to write conversion glue.
No public function in the implementation crates returns Result<T, Box<dyn Error>> or anyhow::Error. The crate boundary is part of the type contract.