oficina / sheets Public

Clone
git clone https://amadan.net/oficina/sheets

Plain git — no account needed to clone.

Download

Download this file

1package xlsx
2
3import (
4 "errors"
5 "strings"
6 "testing"
7)
8
9// TestCellErrorTextOmitsItsCause is the guarantee CellError exists for.
10//
11// Import's errors reach a background job's owner and platform-held logs
12// this app cannot grep (spec §2.4). A wrapped cause is the half that can
13// carry a cell's contents — a parse failure quoting the text it could
14// not parse, say — so CellError's own text must never include it, even
15// though Unwrap still hands it to errors.Is and errors.As.
16//
17// This is an internal test because the cause is unexported, which is
18// itself the point: nothing outside this package can put content into a
19// CellError's text, because nothing outside it can reach the field.
20func TestCellErrorTextOmitsItsCause(t *testing.T) {
21 const canary = "SECRET-PAYROLL-FIGURE-93f7"
22 cause := errors.New("cannot parse " + canary)
23
24 err := cellErr("cannot parse cell", 6, 1, cause)
25
26 if got := err.Error(); strings.Contains(got, canary) {
27 t.Fatalf("CellError text carries its cause: %q", got)
28 }
29 if got := err.Error(); !strings.Contains(got, "B7") {
30 t.Errorf("CellError text = %q, want the coordinate B7 in it", got)
31 }
32 // Unwrap still works, so a sentinel further down the chain is
33 // still matchable — the text is narrowed, not the error.
34 if !errors.Is(err, cause) {
35 t.Error("CellError does not unwrap to its cause")
36 }
37}
38