ArgCheck.jl icon indicating copy to clipboard operation
ArgCheck.jl copied to clipboard

DomainError needs 2 arguments

Open blegat opened this issue 7 months ago • 1 comments

The DomainError that is thrown is incorrect:

julia> @argcheck det(A) < 0 DomainError
ERROR: DomainError with det(A) < 0 must hold. Got
det(A) => 0.0:

Stacktrace:
 [1] throw_check_error(info::Any)
   @ ArgCheck ~/.julia/packages/ArgCheck/DaoPJ/src/checks.jl:283
 [2] top-level scope
   @ REPL[32]:1

It should throw DomainError(A, message), not DomainError(message). I tried:

julia> @check det(A) < 0 Base.Fix1(DomainError, A)
ERROR: MethodError: no method matching build_error(::ArgCheck.CallErrorInfo, ::ArgCheck.CheckFlavor, ::Base.Fix1{Type{DomainError}, Matrix{Float64}})
The function `build_error` exists, but no method is defined for this combination of argument types.

It would be nice if this syntax would work:

@check det(A) < 0 DomainError(A)

blegat avatar Jun 16 '25 07:06 blegat

Thanks, this is a good proposal. You already fixed the docstring in https://github.com/jw3126/ArgCheck.jl/pull/50

Personally, I get most value out of this package just doing @check det(A) < 0 and not tinkering with the error at all. I would probably have written something like:

if det(A) < 0
    throw(DomainError(A))
end

Still I am open for this proposal if you want to implement it.

jw3126 avatar Jun 16 '25 07:06 jw3126