# How to detect that PackageCompiler fails?

**URL:** https://discourse.julialang.org/t/how-to-detect-that-packagecompiler-fails/130686
**Category:** General Usage
**Tags:** question, package, package-compiler
**Created:** [July 13, 2025, 7:49pm UTC](https://discourse.julialang.org/t/how-to-detect-that-packagecompiler-fails/130686 "2025-07-13T19:49:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [July 13, 2025, 7:49pm UTC](https://discourse.julialang.org/t/how-to-detect-that-packagecompiler-fails/130686/1 "2025-07-13T19:49:20Z")

</div>

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

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

```

The `create_sys_image.jl` script contains the line:

```julia
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?

---

<div class="post-metadata">

### Author: ![Bart\_van\_de\_Lint](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bart_van_de_lint/32/212161_2.png) [@Bart\_van\_de\_Lint](https://discourse.julialang.org/u/Bart_van_de_Lint)
#### Post date: [July 13, 2025, 7:53pm UTC](https://discourse.julialang.org/t/how-to-detect-that-packagecompiler-fails/130686/2 "2025-07-13T19:53:39Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [July 13, 2025, 7:58pm UTC](https://discourse.julialang.org/t/how-to-detect-that-packagecompiler-fails/130686/3 "2025-07-13T19:58:00Z")

</div>

You can find a log file here: [Install KiteModels (last release) · OpenSourceAWE/AWEMeta.jl@b5fdff4 · GitHub](https://github.com/OpenSourceAWE/AWEMeta.jl/actions/runs/16252292133/job/45883596466)

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:

```julia
   [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
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:

```julia
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:

```julia
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?

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [July 13, 2025, 8:35pm UTC](https://discourse.julialang.org/t/how-to-detect-that-packagecompiler-fails/130686/4 "2025-07-13T20:35:17Z")

</div>

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

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

```

while it should be:

```bash
#!/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](https://github.com/OpenSourceAWE/AWEMeta.jl/actions/runs/16253208410/job/45885743851)

Pretty happy about our [integration tests](https://github.com/OpenSourceAWE/AWEMeta.jl?tab=readme-ov-file#awemeta) now.
