From 8f452ad7a60f64338ac1ac74c4fe10166375bbc6 Mon Sep 17 00:00:00 2001 From: Gabriele Bozzola Date: Tue, 9 Apr 2024 12:02:09 -0700 Subject: [PATCH] Throw informative error for unsupported vtype Currently, defVar fails with something like ``` ERROR: KeyError: key DateTime not found ``` This PR throws a more informative error message --- src/cfvariable.jl | 1 + test/test_writevar.jl | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/cfvariable.jl b/src/cfvariable.jl index a9c339ce..ab768204 100644 --- a/src/cfvariable.jl +++ b/src/cfvariable.jl @@ -114,6 +114,7 @@ function defVar(ds::NCDataset,name::SymbolOrString,vtype::DataType,dimnames; typeid = nc_def_vlen(ds.ncid, typename, ncType[eltype(vtype)]) else # base-type + haskey(ncType, vtype) || error("$vtype not supported") ncType[vtype] end diff --git a/test/test_writevar.jl b/test/test_writevar.jl index b7cac335..47b7cd50 100644 --- a/test/test_writevar.jl +++ b/test/test_writevar.jl @@ -12,6 +12,8 @@ ds = NCDataset(filename,"c") defDim(ds,"lon",sz[1]) defDim(ds,"lat",sz[2]) +# vartype not supported +@test_throws ErrorException defVar(ds,"var-DT",DateTime,("lon","lat")) # variables for T in [UInt8,Int8,UInt16,Int16,UInt32,Int32,UInt64,Int64,Float32,Float64]