ChifiSource / Olive.jl

pure julia notebooks
MIT License
152 stars 6 forks source link

Olive starts but handle_connection error after a short time #109

Closed kgoulet closed 9 months ago

kgoulet commented 9 months ago

Sometimes I get a start screen and fill in some information, sometimes not, but this connection timeout seems to consistently appear. From the error message it seems that compose.dir is repeated twice. Also, compose.dir does not appear to be a directory but a file.

stacktrace.txt compose.dir.txt

More listings attached.

-----------------------Error message -----------------------


OliveCore
ToolipsSession.Session

julia> Error: handle_connection handler error. 

===========================
 HTTP Error message:

 ERROR: IOError: readdir("/home/kgoulet/.julia/artifacts/1e69ef9fbf05e2896d3cb70eac8080c4d10f8696/share/X11/locale/compose.dir/compose.dir"): not a directory (ENOTDIR)
 Stacktrace:
   [1] uv_error
    @ ./libuv.jl:100 [inlined]   [2] readdir(dir::String; join::Bool, sort::Bool)

----------------------------------------------------

------------------- system info -------------------

kgoulet@linux-1:~$ lsb_release -a
LSB Version:    core-11.1.0ubuntu2-noarch:printing-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:    20.04
Codename:   focal
kgoulet@linux-1:~$ 

Julia 1.9.3

Package installed 

(olive) pkg> st
Project olive v0.1.0
Status `~/olive/olive/Project.toml`
  [724ecaf6] Olive v0.0.9 `https://github.com/ChifiSource/Olive.jl#main`
  [e77a118b] OliveDefaults v0.1.0 `https://github.com/ChifiSource/OliveDefaults.jl#main`
  [44cfe95a] Pkg v1.9.2

(olive) pkg> 

------------------------------------------------
emmaccode commented 9 months ago
this is interesting

It took me a bit to figure out what exactly is happening, in short there is presumably a directory compose in ...X11/locale. Typically, a file cell's type is denoted by the file ending, .jl for the Cell{:jl}, for example.

In this case, compose is a directory, and this is where the name compose.dir is coming from, the Cell{:dir}. I did a look around all of the functions that populate this. I think the issue stems from build_file_cell.

function build_file_cell(e::Int64, path::String, dir::String)
    if ~(isdir(dir * "/" * path))
        splitdir::Vector{SubString} = split(path, "/")
        fname::String = string(splitdir[length(splitdir)])
        fsplit = split(fname, ".")
        fending::String = ""
        if length(fsplit) > 1
            fending = string(fsplit[2])
        end
        Cell(e, fending, fname, replace(dir * "/" * path, "\\" => "/"))
    else
        Cell(e, "dir", path, dir)
    end
end

Here, I think that dir * "/" * path in the conditional is returning false, it is not a directory. I think, however, it is also not a file -- so Olive thinks there is a file or directory there, but apparently there is not -- or something with the path or otherwise is incorrect. Until I can figure out why some of the names from readdir are ... (I guess are just not existing in this instance, or have a different name when interpreted into Julia Strings.) ... I will change this by basically just giving up if this is not a file.

function build_file_cell(e::Int64, path::String, dir::String)
    fpath = dir * "/" * path
    if ~(isdir(fpath))
        if isfile(fpath)
            splitdir::Vector{SubString} = split(path, "/")
            fname::String = string(splitdir[length(splitdir)])
            fsplit = split(fname, ".")
            fending::String = ""
            if length(fsplit) > 1
                fending = string(fsplit[2])
            end
            Cell(e, fending, fname, replace(dir * "/" * path, "\\" => "/"))
        else
            return
        end
    else
        Cell(e, "dir", path, dir)
    end
end

Now this could cause a return of Nothing, so I have to filter! it in the function that calls this.

function directory_cells(dir::String = pwd(), access::Pair{String, String} ...)
    files = readdir(dir)
    return(filter!(e -> ~(isnothing(e)), [build_file_cell(e, path, dir) for (e, path) in enumerate(files)]::AbstractVector))
end

Also, the reason why this error was happening on load is because the sub-directory cells are made when the cell is made -- I don't really like that. While it means we don't have to rebuild cells everytime it is collapsed, it also means that we are holding those cells in memory -- and generating them on startup, I will change that as well.

    on(c, filecell, "click") do cm::ComponentModifier
        childs = Vector{Servable}([begin
        build(c, mcell, d)
        end
        for mcell in directory_cells(cell.outputs * "/" * cell.source)])
        if cm[filecell]["ex"] == "0"
            style!(cm, childbox, "height" => "auto", "opacity" => 100percent)
            cm[filecell] = "ex" => "1"
            return
        end
        set_children!(cm, childbox, childs)
        style!(cm, childbox, "opacity" => 0percent, "height" => 0percent)
        cm[filecell] = "ex" => "0"
    end

thought I would rebel and use childs.

@kgoulet I think that these changes to the file cell building should fix this odd issue; thanks for bringing this to my attention, I am still curious what the exact root causes are -- but either way I think it is great to have this exception case. I have made these changes on my fork of Olive on branch #109 for this issue. I will also be merging this to emmaccode/Unstable, so your Olive will still update (albeit with Unstable changes from my fork) if you want to add it from there.

julia> ]

pkg> add https://github.com/emmaccode/Olive.jl#109
pkg> add https://github.com/emmaccode/Olive.jl#Unstable
using Pkg; Pkg.add(url = "https://github.com/emmaccode/Olive.jl", rev = "109")
using Pkg; Pkg.add(url = "https://github.com/emmaccode/Olive.jl", rev = "Unstable")

Let me know if this has solved your issue, so I can close this. Thanks for the report and support ;)

kgoulet commented 9 months ago

Appears to be no longer an issue.

terminal output for the record.

julia> exit() kgoulet@linux-1:~$ julia _ _ _ _(_)_ | Documentation: https://docs.julialang.org (_) | (_) (_) | _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help. | | | | | | |/ _ | | | | || | | | (| | | Version 1.9.3 (2023-08-24) / |_'|||_'_| | Official https://julialang.org/ release |__/ |

(@v1.9) pkg> add https://github.com/emmaccode/Olive.jl#109 Updating git-repo https://github.com/emmaccode/Olive.jl Resolving package versions... Updating ~/.julia/environments/v1.9/Project.toml [724ecaf6] ~ Olive v0.0.9 https://github.com/ChifiSource/Olive.jl#main ⇒ v0.0.9 https://github.com/emmaccode/Olive.jl#109 Updating ~/.julia/environments/v1.9/Manifest.toml [724ecaf6] ~ Olive v0.0.9 https://github.com/ChifiSource/Olive.jl#main ⇒ v0.0.9 https://github.com/emmaccode/Olive.jl#109 Precompiling project... 1 dependency successfully precompiled in 2 seconds. 274 already precompiled.

(@v1.9) pkg> add https://github.com/emmaccode/Olive.jl#Unstable Updating git-repo https://github.com/emmaccode/Olive.jl Resolving package versions... Updating ~/.julia/environments/v1.9/Project.toml [724ecaf6] ~ Olive v0.0.9 https://github.com/emmaccode/Olive.jl#109 ⇒ v0.0.9 https://github.com/emmaccode/Olive.jl#Unstable Updating ~/.julia/environments/v1.9/Manifest.toml [724ecaf6] ~ Olive v0.0.9 https://github.com/emmaccode/Olive.jl#109 ⇒ v0.0.9 https://github.com/emmaccode/Olive.jl#Unstable

(@v1.9) pkg>

julia> using Olive

julia> IP = "127.0.0.1" # same as default (see ?(Olive.start)) "127.0.0.1"

julia> PORT = 8000 8000

julia> startpath = "/home/kgoulet/olive" "/home/kgoulet/olive"

julia> Olive.start(IP, PORT, devmode = false, path = startpath) Activating project at ~/olive/olive

[ Info: Listening on: 127.0.0.1:8000, thread id: 1 [2023:11:04:11:25]: 🫒 olive> link for kgou: http://127.0.0.1:8000/?key=zCO6kafmb2dXrKE7 Toolips.WebServer hosted at: http://127.0.0.1:8000 status: 4 routes 404 / /MaterialIcons.otf /favicon.ico /modifier/linker

extensions
Toolips.Logger

OliveCore ToolipsSession.Session

`