# Makie.jl updating Observable causes "cannot convert a value to nothing for assignment"

**URL:** <https://discourse.julialang.org/t/makie-jl-updating-observable-causes-cannot-convert-a-value-to-nothing-for-assignment/111076>\
**Category:** General Usage\
**Created:** [March 3, 2024, 12:07am UTC](https://discourse.julialang.org/t/makie-jl-updating-observable-causes-cannot-convert-a-value-to-nothing-for-assignment/111076 "2024-03-03T00:07:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bryaan/32/36858_2.png) [@bryaan](https://discourse.julialang.org/u/bryaan)\
**Post date:** [March 3, 2024, 12:07am UTC](https://discourse.julialang.org/t/makie-jl-updating-observable-causes-cannot-convert-a-value-to-nothing-for-assignment/111076/1 "2024-03-03T00:07:46Z")

</div>

Since Makie does not have a mechanism for detecting axis limit updates I decided to make my own wrapper with Observables.

I am having a strange error when triggering the notify in set\_xlims!. I think this is a deeper bug but unsure, hopefully the stacktrace can point us in the right direction.

```julia
mutable struct Chart
    fig::Figure
    ax::Axis
    limits::Observable{Any}
end

function set_xlims!(C::Chart, xmin, xmax)
    xlims!(C.ax, xmin, xmax)
    # C.limits[] = ((xmin, xmax), C.limits[][2])
    C.limits.val = 1
    notify(C.limits)
end

# Only errors if listening to changes
lift(base_chart.limits) do l
 ...
end

```

```julia
Error in callback:
cannot convert a value to nothing for assignment
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] nonnothingtype_checked(T::Type)
    @ Base ./some.jl:32
  [3] convert(::Type{Nothing}, x::Vector{Float64})
    @ Base ./some.jl:37
  [4] setproperty!(x::Observables.Observable{Nothing}, f::Symbol, v::Vector{Float64})
    @ Base ./Base.jl:40
  [5] setindex!(observable::Observables.Observable, val::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:122
  [6] (::Observables.MapCallback)(value::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:436
  [7] #invokelatest#2
    @ ./essentials.jl:887 [inlined]
  [8] invokelatest
    @ ./essentials.jl:884 [inlined]
  [9] notify
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:206 [inlined]
 [10] set_xlims!(C::Main.Tibra.Chart, xmin::Float32, xmax::Float32)
    @ Main.Tibra ~/src/tibra/Tibra.jl/src/tibrax_desktop/avalon_chart.jl:64

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [March 3, 2024, 8:41am UTC](https://discourse.julialang.org/t/makie-jl-updating-observable-causes-cannot-convert-a-value-to-nothing-for-assignment/111076/2 "2024-03-03T08:41:59Z")

</div>

> [@bryaan](#):
>
> ```julia
> setproperty!(x::Observables.Observable{Nothing}, f::Symbol, v::Vector{Float64})
> 
> ```

Somewhere you have an `Observable{Nothing}` and you trying to set it with a `Vector{Float64}`.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 3, 2024, 9:41am UTC](https://discourse.julialang.org/t/makie-jl-updating-observable-causes-cannot-convert-a-value-to-nothing-for-assignment/111076/3 "2024-03-03T09:41:24Z")

</div>

> [@bryaan](#):
>
> Since Makie does not have a mechanism for detecting axis limit updates

You can use `ax.finallimits`

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [March 9, 2024, 9:10pm UTC](https://discourse.julialang.org/t/makie-jl-updating-observable-causes-cannot-convert-a-value-to-nothing-for-assignment/111076/4 "2024-03-09T21:10:15Z")

</div>

> [@bryaan](#):
>
> ```julia
> # Only errors if listening to changes
> lift(base_chart.limits) do l
> ...
> end
> 
> ```

For future reference: you may have been conditionally returning something in that `lift` statement. If you want to just listen and act, and not create an observable with whatever that `do` block returns, then use `on` or `onany` (for multiple observable inputs)!
