From 46e79169cd77ca3df545a706944bd2291ae2a606 Mon Sep 17 00:00:00 2001 From: "Christian G. Warden" Date: Fri, 2 Aug 2024 14:47:37 -0500 Subject: [PATCH] Error When Using Invalid Column With add-col! Return an error when `add-col!` is called with an invalid column. --- evaldo/builtins_spreadsheet.go | 2 +- tests/structures.rye | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/evaldo/builtins_spreadsheet.go b/evaldo/builtins_spreadsheet.go index 066360a5..4280503f 100644 --- a/evaldo/builtins_spreadsheet.go +++ b/evaldo/builtins_spreadsheet.go @@ -845,7 +845,7 @@ func GenerateColumn(ps *env.ProgramState, s env.Spreadsheet, name env.Word, extr } // fmt.Println(val) if er != nil { - return nil + return MakeBuiltinError(ps, er.Error(), "add-col!") } if firstVal == nil { var ok bool diff --git a/tests/structures.rye b/tests/structures.rye index b2dcb33a..d9097acc 100644 --- a/tests/structures.rye +++ b/tests/structures.rye @@ -611,6 +611,13 @@ section "Spreadsheet related functions" equal { to-spreadsheet vals { dict { "a" 1 b 2 "c" 3 } dict { "a" 4 "b" 5 } } } spreadsheet { "a" "b" "c" } { 1 2 3 4 5 _ } } + group "add-col" + mold\nowrap ?add-col! + { { block } } + { + equal { try { spreadsheet { "n" } [ 1 ] |add-col! 'm { x } { x } } |type? } 'error + } + group "index" mold\nowrap ?add-indexes! { { block } }