---
epic: 1
story: 1.7
title: "Error Handling & Graceful Degradation"
status: draft
---

## Epic 1 — Core Calculation Engine (Rust Crate)
**Goal:** Build `calcpad-engine` as a standalone Rust crate that powers all platforms. This is the foundation.

### Story 1.7: Error Handling & Graceful Degradation

As a CalcPad user,
I want lines with errors to show a subtle indicator without breaking the rest of my sheet,
So that a typo on one line does not disrupt my entire calculation flow.

**Acceptance Criteria:**

**Given** a sheet with 10 lines where line 5 contains a syntax error
**When** the sheet is evaluated
**Then** lines 1-4 and 6-10 produce correct results
**And** line 5 returns a `CalcResult::Error` with a human-readable message

**Given** an error result for a line
**When** the result is inspected
**Then** it includes the error message, the byte span of the problem, and an error category (Syntax, Type, Reference, Runtime)

**Given** a line that references an undefined variable `x`
**When** the engine evaluates it
**Then** it returns a `CalcResult::Error` with category `Reference` and message indicating `x` is undefined
**And** other lines that do not depend on `x` are unaffected

**Given** a line that produces a division-by-zero
**When** the engine evaluates it
**Then** it returns a `CalcResult::Error` with category `Runtime` and an appropriate message
**And** the engine does not panic

**Given** any possible input string (including empty, whitespace-only, binary data, or extremely long input)
**When** the engine evaluates it
**Then** it never panics
**And** it returns either a valid result or an error within a bounded time

**Given** a line that previously had an error but is now corrected
**When** the sheet is re-evaluated
**Then** the corrected line produces a valid result
**And** any dependent lines are also re-evaluated successfully
