Skip to content

[BUG] RecipesBase.@recipe throws LoadError when kwarg has no default value #5114

@PTWaade

Description

@PTWaade

Details

Hey JuliaPlots,

Thank you for your amazing work.

I ran into an error when trying to define a recipe with RecipesBase which contains keyword arguments that do not have default values.
This throws a somewhat unhelpful LoadError. If it is a known issue (or deliberate that defaults are required), perhaps a different error can be thrown.

Below is an MWE based on the example from the documentation:. Let me know if there is anything else I can do!

MWE

using RecipesBase

struct Result
    x::Vector{Float64}
    y::Vector{Float64}
    ε::Vector{Float64}
end

@recipe function f(r::Result; ε_max)
    # set a default value for an attribute with `-->`
    xlabel --> "x"
    yguide --> "y"
    markershape --> :diamond
    # add a series for an error band
    @series begin
        # force an argument with `:=`
        seriestype := :path
        # ignore series in legend and color cycling
        primary := false
        linecolor := nothing
        fillcolor := :lightgray
        fillalpha := 0.5
        fillrange := r.y .- r.ε
        # ensure no markers are shown for the error band
        markershape := :none
        # return series data
        r.x, r.y .+ r.ε
    end
    # get the seriescolor passed by the user
    c = get(plotattributes, :seriescolor, :auto)
    # highlight big errors, otherwise use the user-defined color
    markercolor := ifelse.(r.ε .> ε_max, :red, c)
    # return data
    r.x, r.y
end

The output is:

ERROR: LoadError: type Symbol has no field args
Stacktrace:
[1] getproperty(x::Symbol, f::Symbol)
@ Base ./Base.jl:49
[2] create_kw_body(func_signature::Expr)
@ RecipesBase ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:114
[3] var"@recipe"(source::LineNumberNode, module::Module, funcexpr::Expr)
@ RecipesBase ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:280
in expression starting at /Users/au568658/Library/CloudStorage/OneDrive-Aarhusuniversitet/Projects/Misc/test.jl:9

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) X
pythonplot X
plotlyjs X
pgfplotsx X
unicodeplots X
inspectdr X
gaston X

Versions

RecipesBase.jl version: v1.3.4
Backend version (]st -m <backend(s)>): N/A
Output of versioninfo():

Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: macOS (arm64-apple-darwin24.0.0)
CPU: 8 × Apple M1
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 2 default, 0 interactive, 1 GC (on 4 virtual cores)
Environment:
JULIA_EDITOR = code
JULIA_VSCODE_REPL = 1
JULIA_NUM_THREADS = 2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions