From 808e242340961bdea774ca661888c3d2f6ba43ea Mon Sep 17 00:00:00 2001 From: KronosTheLate Date: Thu, 11 Apr 2024 18:01:24 +0200 Subject: [PATCH] Make errors in peakwidths! more friendly --- src/peakwidth.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/peakwidth.jl b/src/peakwidth.jl index d3fbdfd..333a6c2 100644 --- a/src/peakwidth.jl +++ b/src/peakwidth.jl @@ -205,9 +205,11 @@ end function peakwidths!(pks::NamedTuple; strict=true, relheight=0.5, min=nothing, max=nothing) !hasproperty(pks, :proms) && throw(ArgumentError( - "Argument `pks` is expected to have prominences (`:proms`) already calculated")) + "Argument `pks` is expected to have prominences (`:proms`) already calculated. \nExample fix: `peakwidths!(peakproms!(pks))`")) if xor(hasproperty(pks, :widths), hasproperty(pks, :edges)) - throw(ArgumentError("Argument `pks` is expected have neither or both of the fields `:widths` and `:edges`.")) + hasproperty(pks, :widths) ? + throw(ArgumentError("Argument `pks` is has property `:widths`, but not field `:edges`. As functions from Peaks.jl only ever add both, this implies unexpected tampering with the peaks provided. To avoid unexpected behaviour, this is an error." )) : + throw(ArgumentError("Argument `pks` is has property `:edges`, but not field `:widths`. As functions from Peaks.jl only ever add both, this implies unexpected tampering with the peaks provided. To avoid unexpected behaviour, this is an error." )) end if !hasproperty(pks, :widths) # Wait to filter until after merging `pks`