Skip to content

Commit

Permalink
Improve error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
orenbenkiki committed Jun 8, 2024
1 parent a73a224 commit fb0dbe9
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 95 deletions.
2 changes: 1 addition & 1 deletion docs/v0.1.0/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-06-07T09:50:19","documenter_version":"1.4.1"}}
{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-06-08T11:10:42","documenter_version":"1.4.1"}}
2 changes: 1 addition & 1 deletion src/concat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ By default, concatenation will fail rather than `overwrite` existing properties
for axis in axes
require_no_axis(destination, axis)
for source in sources
require_axis(source, axis)
require_axis(source, "for: concatenate!", axis)
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/queries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@ function fake_query_operation!(fake_query_state::FakeQueryState, axis::Axis)::No
end

function push_axis(query_state::QueryState, axis::Axis, ::Nothing)::Nothing
require_axis(query_state.daf, axis.axis_name)
require_axis(query_state.daf, "for the query: $(query_state.query_sequence)", axis.axis_name)
query_sequence = QuerySequence((axis,))
dependency_keys = Set((Formats.axis_array_cache_key(axis.axis_name),))
axis_state = AxisState(query_sequence, dependency_keys, axis.axis_name, nothing)
Expand Down
39 changes: 20 additions & 19 deletions src/readers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function axis_array(
else
result_prefix = "default "
@assert default == undef
require_axis(daf, axis)
require_axis(daf, "for: axis_array", axis)
end
end

Expand All @@ -234,7 +234,7 @@ Return a dictionary converting axis entry names to their integer index.
"""
function axis_dict(daf::DafReader, axis::AbstractString)::AbstractDict{<:AbstractString, <:Integer}
return Formats.with_data_read_lock(daf, "axis_dict of:", axis) do
require_axis(daf, axis)
require_axis(daf, "for: axis_dict", axis)
result = Formats.axis_dict_with_cache(daf, axis)
@debug "axis_dict daf: $(depict(daf)) result: $(depict(result))"
return result
Expand All @@ -250,16 +250,16 @@ This first verifies the `axis` exists in `daf`.
"""
function axis_length(daf::DafReader, axis::AbstractString)::Int64
return Formats.with_data_read_lock(daf, "axis_length of:", axis) do
require_axis(daf, axis)
require_axis(daf, "for: axis_length", axis)
result = Formats.format_axis_length(daf, axis)
@debug "axis_length daf: $(depict(daf)) axis: $(axis) result: $(result)"
return result
end
end

function require_axis(daf::DafReader, axis::AbstractString; for_change::Bool = false)::Nothing
function require_axis(daf::DafReader, what_for::AbstractString, axis::AbstractString; for_change::Bool = false)::Nothing
if !Formats.format_has_axis(daf, axis; for_change = for_change)
error("missing axis: $(axis)\nin the daf data: $(daf.name)")
error("missing axis: $(axis)\n$(what_for)\nof the daf data: $(daf.name)")
end
return nothing
end
Expand All @@ -274,7 +274,7 @@ This first verifies the `axis` exists in `daf`.
"""
function has_vector(daf::DafReader, axis::AbstractString, name::AbstractString)::Bool
return Formats.with_data_read_lock(daf, "has_vector of:", name, "of:", axis) do
require_axis(daf, axis)
require_axis(daf, "for has_vector: $(name)", axis)
result = name == "name" || Formats.format_has_vector(daf, axis, name)
@debug "has_vector daf: $(depict(daf)) axis: $(axis) name: $(name) result: $(result)"
return result
Expand Down Expand Up @@ -313,7 +313,7 @@ This first verifies the `axis` exists in `daf`.
"""
function vectors_set(daf::DafReader, axis::AbstractString)::AbstractSet{<:AbstractString}
return Formats.with_data_read_lock(daf, "vectors_set of:", axis) do
require_axis(daf, axis)
require_axis(daf, "for: vectors_set", axis)
result = Formats.get_vectors_set_through_cache(daf, axis)
@debug "vectors_set daf: $(depict(daf)) axis: $(axis) result: $(depict(result))"
return result
Expand Down Expand Up @@ -344,10 +344,10 @@ function get_vector(
default::Union{StorageScalar, StorageVector, Nothing, UndefInitializer} = undef,
)::Maybe{NamedArray}
return Formats.with_data_read_lock(daf, "get_vector of:", name, "of:", axis) do
require_axis(daf, axis)
require_axis(daf, "for the vector: $(name)", axis)

if default isa StorageVector
require_axis_length(daf, "default length", length(default), axis)
require_axis_length(daf, length(default), "default for the vector: $(name)", axis)
if default isa NamedVector
require_dim_name(daf, axis, "default dim name", dimnames(default, 1))
require_axis_names(daf, axis, "entry names of the: default", names(default, 1))
Expand Down Expand Up @@ -449,8 +449,8 @@ function has_matrix(
return Formats.with_data_read_lock(daf, "has_matrix of:", name, "of:", rows_axis, "and:", columns_axis) do
Formats.relayout = relayout && rows_axis != columns_axis

require_axis(daf, rows_axis)
require_axis(daf, columns_axis)
require_axis(daf, "for the rows of the matrix: $(name)", rows_axis)
require_axis(daf, "for the columns of the matrix: $(name)", columns_axis)

result = with_read_lock(daf.internal.cache_lock) do
return haskey(daf.internal.cache, Formats.matrix_cache_key(rows_axis, columns_axis, name)) ||
Expand Down Expand Up @@ -490,8 +490,8 @@ function matrices_set(
return Formats.with_data_read_lock(daf, "matrices_set of:", rows_axis, "and:", columns_axis) do
relayout = relayout && rows_axis != columns_axis

require_axis(daf, rows_axis)
require_axis(daf, columns_axis)
require_axis(daf, "for the rows of: matrices_set", rows_axis)
require_axis(daf, "for the columns of: matrices_set", columns_axis)

if !relayout
names = Formats.get_matrices_set_through_cache(daf, rows_axis, columns_axis)
Expand Down Expand Up @@ -594,13 +594,13 @@ function do_get_matrix(
)::Maybe{NamedArray}
relayout = relayout && rows_axis != columns_axis

require_axis(daf, rows_axis)
require_axis(daf, columns_axis)
require_axis(daf, "for the rows of the matrix: $(name)", rows_axis)
require_axis(daf, "for the columns of the matrix: $(name)", columns_axis)

if default isa StorageMatrix
require_column_major(default)
require_axis_length(daf, "default rows", size(default, Rows), rows_axis)
require_axis_length(daf, "default columns", size(default, Columns), columns_axis)
require_axis_length(daf, size(default, Rows), "rows of the default for the matrix: $(name)", rows_axis)
require_axis_length(daf, size(default, Columns), "columns of the default for the matrix: $(name)", columns_axis)
if default isa NamedMatrix
require_dim_name(daf, rows_axis, "default rows dim name", dimnames(default, 1); prefix = "rows")
require_dim_name(daf, columns_axis, "default columns dim name", dimnames(default, 2); prefix = "columns")
Expand Down Expand Up @@ -767,13 +767,14 @@ end

function require_axis_length(
daf::DafReader,
what_name::AbstractString,
what_length::StorageInteger,
vector_name::AbstractString,
axis::AbstractString,
)::Nothing
if what_length != Formats.format_axis_length(daf, axis)
error(
"$(what_name): $(what_length)\n" *
"the length: $(what_length)\n" *
"of the $(vector_name)\n" *
"is different from the length: $(Formats.format_axis_length(daf, axis))\n" *
"of the axis: $(axis)\n" *
"in the daf data: $(daf.name)",
Expand Down
36 changes: 18 additions & 18 deletions src/writers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function delete_axis!(daf::DafWriter, axis::AbstractString; must_exist::Bool = t
@debug "delete_axis! daf: $(depict(daf)) axis: $(axis) must exist: $(must_exist)"

if must_exist
require_axis(daf, axis; for_change = true)
require_axis(daf, "for: delete_axis!", axis; for_change = true)
elseif !Formats.format_has_axis(daf, axis; for_change = true)
return nothing
end
Expand Down Expand Up @@ -248,10 +248,10 @@ function set_vector!(
@debug "set_vector! daf: $(depict(daf)) axis: $(axis) name: $(name) vector: $(depict(vector)) overwrite: $(overwrite)"

require_not_name(daf, axis, name)
require_axis(daf, axis)
require_axis(daf, "for the vector: $(name)", axis)

if vector isa StorageVector
require_axis_length(daf, "vector length", length(vector), axis)
require_axis_length(daf, length(vector), "vector: $(name)", axis)
if vector isa NamedVector
require_dim_name(daf, axis, "vector dim name", dimnames(vector, 1))
require_axis_names(daf, axis, "entry names of the: vector", names(vector, 1))
Expand Down Expand Up @@ -323,7 +323,7 @@ function get_empty_dense_vector!(
try
@debug "empty_dense_vector! daf: $(depict(daf)) axis: $(axis) name: $(name) eltype: $(eltype) overwrite: $(overwrite) {"
require_not_name(daf, axis, name)
require_axis(daf, axis)
require_axis(daf, "for the vector: $(name)", axis)

Formats.invalidate_cached!(daf, Formats.vectors_set_cache_key(axis))
Formats.invalidate_cached!(daf, Formats.vector_cache_key(axis, name))
Expand Down Expand Up @@ -428,7 +428,7 @@ function get_empty_sparse_vector!(
try
@debug "empty_sparse_vector! daf: $(depict(daf)) axis: $(axis) name: $(name) eltype: $(eltype) nnz: $(nnz) indtype: $(indtype) overwrite: $(overwrite) {"
require_not_name(daf, axis, name)
require_axis(daf, axis)
require_axis(daf, "for the vector: $(name)", axis)

Formats.invalidate_cached!(daf, Formats.vector_cache_key(axis, name))
Formats.invalidate_cached!(daf, Formats.vectors_set_cache_key(axis))
Expand Down Expand Up @@ -498,7 +498,7 @@ function delete_vector!(
@debug "delete_vector! $daf: $(depict(daf)) axis: $(axis) name: $(name) must exist: $(must_exist)"

require_not_name(daf, axis, name)
require_axis(daf, axis)
require_axis(daf, "for the vector: $(name)", axis)

if must_exist
require_vector(daf, axis, name)
Expand Down Expand Up @@ -561,13 +561,13 @@ function set_matrix!(
relayout = relayout && rows_axis != columns_axis
@debug "set_matrix! daf: $(depict(daf)) rows_axis: $(rows_axis) columns_axis: $(columns_axis) name: $(name) matrix: $(depict(matrix)) overwrite: $(overwrite) relayout: $(relayout)"

require_axis(daf, rows_axis)
require_axis(daf, columns_axis)
require_axis(daf, "for the rows of the matrix: $(name)", rows_axis)
require_axis(daf, "for the columns of the matrix: $(name)", columns_axis)

if matrix isa StorageMatrix
require_column_major(matrix)
require_axis_length(daf, "matrix rows", size(matrix, Rows), rows_axis)
require_axis_length(daf, "matrix columns", size(matrix, Columns), columns_axis)
require_axis_length(daf, size(matrix, Rows), "rows of the matrix: $(name)", rows_axis)
require_axis_length(daf, size(matrix, Columns), "columns of the matrix: $(name)", columns_axis)
if matrix isa NamedMatrix
require_dim_name(daf, rows_axis, "matrix rows dim name", dimnames(matrix, 1); prefix = "rows")
require_dim_name(daf, columns_axis, "matrix columns dim name", dimnames(matrix, 2); prefix = "columns")
Expand Down Expand Up @@ -651,8 +651,8 @@ function get_empty_dense_matrix!(
Formats.begin_data_write_lock(daf, "empty_dense_matrix! of:", name, "of:", rows_axis, "and:", columns_axis)
try
@debug "empty_dense_matrix! daf: $(depict(daf)) rows_axis: $(rows_axis) columns_axis: $(columns_axis) name: $(name) eltype: $(eltype) overwrite: $(overwrite) {"
require_axis(daf, rows_axis)
require_axis(daf, columns_axis)
require_axis(daf, "for the rows of the matrix: $(name)", rows_axis)
require_axis(daf, "for the columns of the matrix: $(name)", columns_axis)

if !overwrite
require_no_matrix(daf, rows_axis, columns_axis, name; relayout = false)
Expand Down Expand Up @@ -762,8 +762,8 @@ function get_empty_sparse_matrix!(
Formats.begin_data_write_lock(daf, "empty_sparse_matrix! of:", name, "of:", rows_axis, "and:", columns_axis)
try
@debug "empty_sparse_matrix! daf: $(depict(daf)) rows_axis: $(rows_axis) columns_axis: $(columns_axis) name: $(name) eltype: $(eltype) overwrite: $(overwrite) {"
require_axis(daf, rows_axis)
require_axis(daf, columns_axis)
require_axis(daf, "for the rows of the matrix: $(name)", rows_axis)
require_axis(daf, "for the columns of the matrix: $(name)", columns_axis)

if !overwrite
require_no_matrix(daf, rows_axis, columns_axis, name; relayout = false)
Expand Down Expand Up @@ -834,8 +834,8 @@ function relayout_matrix!(
Formats.with_data_write_lock(daf, "relayout_matrix! of:", name, "of:", rows_axis, "and:", columns_axis) do
@debug "relayout_matrix! daf: $(depict(daf)) rows_axis: $(rows_axis) columns_axis: $(columns_axis) name: $(name) overwrite: $(overwrite) {"

require_axis(daf, rows_axis)
require_axis(daf, columns_axis)
require_axis(daf, "for the rows of the matrix: $(name)", rows_axis)
require_axis(daf, "for the columns of the matrix: $(name)", columns_axis)

if rows_axis == columns_axis
error(
Expand Down Expand Up @@ -923,8 +923,8 @@ function delete_matrix!(
relayout = relayout && rows_axis != columns_axis
@debug "delete_matrix! daf: $(depict(daf)) rows_axis: $(rows_axis) columns_axis: $(columns_axis) name: $(name) must exist: $(must_exist)"

require_axis(daf, rows_axis)
require_axis(daf, columns_axis)
require_axis(daf, "for the rows of the matrix: $(name)", rows_axis)
require_axis(daf, "for the columns of the matrix: $(name)", columns_axis)

if must_exist
require_matrix(daf, rows_axis, columns_axis, name; relayout = relayout)
Expand Down
33 changes: 22 additions & 11 deletions test/copies.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ nested_test("copies") do
nested_test("missing") do
@test_throws dedent("""
missing axis: cell
in the daf data: source!
for: axis_array
of the daf data: source!
""") copy_axis!(source = source, destination = destination, axis = "cell")
end

Expand All @@ -121,15 +122,17 @@ nested_test("copies") do
nested_test("()") do
@test_throws dedent("""
missing axis: cell
in the daf data: destination!
for: axis_array
of the daf data: destination!
""") copy_vector!(source = source, destination = destination, axis = "cell", name = "age")
end

nested_test("default") do
nested_test("undef") do
@test_throws dedent("""
missing axis: cell
in the daf data: destination!
for: axis_array
of the daf data: destination!
""") copy_vector!(
source = source,
destination = destination,
Expand All @@ -142,7 +145,8 @@ nested_test("copies") do
nested_test("nothing") do
@test_throws dedent("""
missing axis: cell
in the daf data: destination!
for: axis_array
of the daf data: destination!
""") copy_vector!(;
source = source,
destination = destination,
Expand All @@ -155,7 +159,8 @@ nested_test("copies") do
nested_test("value") do
@test_throws dedent("""
missing axis: cell
in the daf data: destination!
for: axis_array
of the daf data: destination!
""") copy_vector!(;
source = source,
destination = destination,
Expand Down Expand Up @@ -525,7 +530,8 @@ nested_test("copies") do
nested_test("()") do
@test_throws dedent("""
missing axis: cell
in the daf data: destination!
for: axis_array
of the daf data: destination!
""") copy_matrix!(
source = source,
destination = destination,
Expand All @@ -538,7 +544,8 @@ nested_test("copies") do

@test_throws dedent("""
missing axis: gene
in the daf data: destination!
for: axis_array
of the daf data: destination!
""") copy_matrix!(
source = source,
destination = destination,
Expand All @@ -552,7 +559,8 @@ nested_test("copies") do
nested_test("undef") do
@test_throws dedent("""
missing axis: cell
in the daf data: destination!
for: axis_array
of the daf data: destination!
""") copy_matrix!(
source = source,
destination = destination,
Expand All @@ -566,7 +574,8 @@ nested_test("copies") do

@test_throws dedent("""
missing axis: gene
in the daf data: destination!
for: axis_array
of the daf data: destination!
""") copy_matrix!(
source = source,
destination = destination,
Expand All @@ -580,7 +589,8 @@ nested_test("copies") do
nested_test("nothing") do
@test_throws dedent("""
missing axis: cell
in the daf data: destination!
for: axis_array
of the daf data: destination!
""") copy_matrix!(
source = source,
destination = destination,
Expand All @@ -594,7 +604,8 @@ nested_test("copies") do

@test_throws dedent("""
missing axis: gene
in the daf data: destination!
for: axis_array
of the daf data: destination!
""") copy_matrix!(
source = source,
destination = destination,
Expand Down
Loading

0 comments on commit fb0dbe9

Please sign in to comment.