Skip to content

fix: replace unwrap() with safe handling in tensor Display impl#802

Open
VedantMadane wants to merge 1 commit intokornia:mainfrom
VedantMadane:fix/tensor-unwrap-safety
Open

fix: replace unwrap() with safe handling in tensor Display impl#802
VedantMadane wants to merge 1 commit intokornia:mainfrom
VedantMadane:fix/tensor-unwrap-safety

Conversation

@VedantMadane
Copy link

Fixes #801

Summary

Replaces two unwrap() calls in the Display trait implementation for Tensor with safe error handling, per project guidelines in AGENTS.md and CONTRIBUTING.md.

Changes

  1. Line ~1030: .max().unwrap().max().unwrap_or(0) — safely handles empty tensors without panicking
  2. Line ~1077: split_once('e').unwrap()split_once('e').ok_or(std::fmt::Error)? — propagates errors via fmt::Result instead of panicking

- Use unwrap_or(0) for empty iterator in max() to avoid panic on empty tensors
- Use ok_or(std::fmt::Error)? for split_once('e') to propagate errors properly

Fixes kornia#801
@VedantMadane VedantMadane force-pushed the fix/tensor-unwrap-safety branch from 9bde56b to d7de3ea Compare March 11, 2026 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Unwrap and expect used in library crate (kornia-tensor)

1 participant