How to detect that PackageCompiler fails?

I am using a Bash script that calls package compiler.
In Bash I execute:

julia --project -e "include(\"./test/create_sys_image.jl\");"

The create_sys_image.jl script contains the line:

PackageCompiler.create_sysimage(
    [:KiteUtils, :KitePodModels, :KiteModels, :ControlPlots];
    sysimage_path="kps-image_tmp.so",
    include_transitive_dependencies=true,
    precompile_execution_file=joinpath("test", "test_for_precompile.jl")
)

The script test_for_precompile.jl fails with an exeption. But the Bash script does not terminate.

How can I detect a failure of the precompile script?

You can delete any old system image before you run the script, and check after running the script if a system image was created. Or is the system image still successfully created, even though test_for_precompile fails?

You can find a log file here: Install KiteModels (last release) · OpenSourceAWE/AWEMeta.jl@b5fdff4 · GitHub

Not so sure if nevertheless a system image is created. But to check if a file exists sounds like an ugly workaround for me. The function call should report a failure in some way, either as return code or as exception.

Error message:

   [4] run_precompilation_script(project::String, sysimg::String, precompile_file::String, precompile_dir::String)
    @ PackageCompiler /tmp/testdepot/packages/PackageCompiler/cTtGY/src/PackageCompiler.jl:314
  [5] create_sysimg_object_file(object_file::String, packages::Vector{String}, packages_sysimg::Set{Base.PkgId}; project::String, base_sysimage::String, precompile_execution_file::Vector{String}, precompile_statements_file::Vector{String}, cpu_target::String, script::Nothing, sysimage_build_args::Cmd, extra_precompiles::String, incremental::Bool, import_into_main::Bool)
    @ PackageCompiler /tmp/testdepot/packages/PackageCompiler/cTtGY/src/PackageCompiler.jl:353
  [6] create_sysimg_object_file
    @ /tmp/testdepot/packages/PackageCompiler/cTtGY/src/PackageCompiler.jl:319 [inlined]
  [7] create_sysimage(packages::Vector{Symbol}; sysimage_path::String, project::String, precompile_execution_file::String, precompile_statements_file::Vector{String}, incremental::Bool, filter_stdlibs::Bool, cpu_target::String, script::Nothing, sysimage_build_args::Cmd, include_transitive_dependencies::Bool, base_sysimage::Nothing, julia_init_c_file::Nothing, julia_init_h_file::Nothing, version::Nothing, soname::Nothing, compat_level::String, extra_precompiles::String, import_into_main::Bool)
    @ PackageCompiler /tmp/testdepot/packages/PackageCompiler/cTtGY/src/PackageCompiler.jl:644
  [8] top-level scope
    @ /tmp/test/test/test/create_sys_image.jl:20
  [9] include(fname::String)
    @ Main ./sysimg.jl:38
 [10] top-level scope
    @ none:1
in expression starting at /tmp/test/test/test/create_sys_image.jl:20

Not clear to me is, if I execute a Julia script with:

julia --project -e "include(\"./test/create_sys_image.jl\");"

and the script terminates with an exception, is the return code of the command one?

I think it should be:

ufechner@framework:~$ julia -e 'a'
ERROR: UndefVarError: `a` not defined in `Main`
ufechner@framework:~$ echo $?
1

So my current conclusion: If the precompile script throws an exception, the call of the function:

PackageCompiler.create_sysimage(
    [:KiteUtils, :KitePodModels, :KiteModels, :ControlPlots];
    sysimage_path="kps-image_tmp.so",
    include_transitive_dependencies=true,
    precompile_execution_file=joinpath("test", "test_for_precompile.jl")
)

does not result in an exception.

Why not?

I think, the problem was in our test script. It had the header:

# SPDX-FileCopyrightText: 2025 Uwe Fechner
# SPDX-License-Identifier: MIT
#!/bin/bash -eu

while it should be:

#!/bin/bash -eu
# SPDX-FileCopyrightText: 2025 Uwe Fechner
# SPDX-License-Identifier: MIT

Now testing.

Update:
This change fixed the problem. See: Install KiteModels (latest release) · OpenSourceAWE/AWEMeta.jl@6f2b6be · GitHub

Pretty happy about our integration tests now.

1 Like