Skip to content

Commit

Permalink
Throw informative error for unsupported vtype
Browse files Browse the repository at this point in the history
Currently, defVar fails with something like
```
ERROR: KeyError: key DateTime not found
```
This PR throws a more informative error message
  • Loading branch information
Sbozzolo committed Apr 9, 2024
1 parent d85c6ca commit 8f452ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cfvariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions test/test_writevar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 8f452ad

Please sign in to comment.