# Alternative to Base.get\_extension

**URL:** <https://discourse.julialang.org/t/alternative-to-base-get-extension/133191>\
**Category:** General Usage\
**Tags:** module, package-extensions\
**Created:** [October 13, 2025, 6:33pm UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191 "2025-10-13T18:33:28Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 13, 2025, 6:33pm UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/1 "2025-10-13T18:33:28Z")

</div>

> [@This month in Julia world - 2025-09](https://discourse.julialang.org/t/this-month-in-julia-world-2025-09/133110/1):
>
> Do not use `Base.get_extension`

That was quick!

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/0/b0fa3f32b7be939d5661e5280a4c0ed7be64eb09.jpeg)

---

<div class="post-metadata">

**Author:** ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Post date:** [October 14, 2025, 3:06am UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/2 "2025-10-14T03:06:30Z")

</div>

To be fair, there was a rather heated argument back and forth about `Base.get_extension` without a very clear outcome. It is great to use interactively while developing and testing – no argument there. But idioms related to, e.g. informative error messages for not-yet-loaded weak dependencies, can lead to footguns, and alternative setups that peek less in the internals are more reliable.

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [October 14, 2025, 6:25am UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/3 "2025-10-14T06:25:09Z")

</div>

I have not yet understood that discussion. I only use that function in two places: Specifying modules in `makedocs` and extending and extension (so `ABCExt` extending stuff defined in `ABExt`).

---

<div class="post-metadata">

**Author:** ![jakobjpeters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobjpeters/32/207797_2.png) [@jakobjpeters](https://discourse.julialang.org/u/jakobjpeters)\
**Post date:** [October 14, 2025, 6:45am UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/4 "2025-10-14T06:45:50Z")

</div>

Especially without `get_extension`, there is inadequate functionality to document (I think I ran into errors documenting helper functions, might be incorrect about this though) and test extensions ☹

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [October 14, 2025, 2:19pm UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/5 "2025-10-14T14:19:55Z")

</div>

If you can’t use `Base.get_extension`, you could always just define your own, i.e. in your main package have a function stub

```julia-auto
#MyPackage/src/MyPackage.jl
module MyPackage

function get_foo_extension end

end

```

and then in your extension file you’d have

```julia-auto
#MyPackage/ext/MyPackageFooExt.jl
module MyPackageFooExt

using MyPackage

MyPackage.get_foo_extension() = MyPackageFooExt

end

```

Users can then access the extension module with

```julia-auto
MyPackage.get_foo_extension()

```

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 14, 2025, 5:35pm UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/6 "2025-10-14T17:35:33Z")

</div>

> [@Mason](#):
>
> If you can’t use `Base.get_extension`

Thanks… I currently [use](https://github.com/JuliaGraphics/Luxor.jl/blob/0c2e0da7b062754a8a1d8df8d73f7bb9a1d38070/src/placeholders_for_extensions.jl#L30):

```Julia
function render_typst_document(catch_all)
    if Base.get_extension(Luxor, :LuxorExtTypstry) isa Module
        throw(MethodError(render_typst_document, catch_all))
    else
        throw(ErrorException("Module Typstry is not loaded."))
    end
end

```

so not for users, more to allow the extension to add methods…🤔

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [October 14, 2025, 6:45pm UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/7 "2025-10-14T18:45:38Z")

</div>

> [@cormullion](#):
>
> Thanks… I currently [use](https://github.com/JuliaGraphics/Luxor.jl/blob/0c2e0da7b062754a8a1d8df8d73f7bb9a1d38070/src/placeholders_for_extensions.jl#L30):
> 
> […]
> 
> so not for users, more to allow the extension to add methods…🤔

Nonetheless, it would be preferable to switch to the supported approach. Furthermore, it is also preferable to avoid throwing `MethodError` explicitly, instead letting it be thrown by dispatch.

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [October 14, 2025, 7:46pm UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/8 "2025-10-14T19:46:58Z")

</div>

The only valid method of `render_typst_document` appears to require passing an argument from `Typstry`, so that message seems a best contradictory and at worst very confusing, since using `get_extension` from there would appear to always incorrectly diagnose the issue.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 14, 2025, 8:35pm UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/9 "2025-10-14T20:35:49Z")

</div>

OK, thanks, What code should I use to get this behaviour (which is what it does currently):

```Julia
julia> using Luxor

julia> render_typst_document("a + b")
ERROR: Module Typstry is not loaded. 
julia>

```

It’s true that there are two errors here (no extension not loaded and wrong argument type), but one is more important than the other, and needs addressing first.

---

<div class="post-metadata">

**Author:** ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Post date:** [October 14, 2025, 8:54pm UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/10 "2025-10-14T20:54:34Z")

</div>

If invalidations are fine, you can do:

```julia-auto
module Luxor
function render_typst_document(arg::Any)
    error("load Typst")
end
end

module Typstry # or in a Luxor extension dependent on Typstry
import Luxor
function Luxor.render_typst_document(arg::AbstractString)
    # actual code
end
end

```

If invalidations are a problem (they are) you can instead register an error hint on method errors for the function `render_typst_document` in `Luxor. __init__ `. If using ` __init__ ` is undesirable (e.g. because you want more aot-compilable trimmable code) then you can do the registration in a `OncePerProcess`.

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [October 14, 2025, 8:58pm UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/11 "2025-10-14T20:58:52Z")

</div>

I think I would leave the error itself to Julia. We usually register just an additional error hint (on init) like

> <https://github.com/JuliaManifolds/Manopt.jl/blob/392ee0e31e61beeffcca1e27a71796d71e6e7ddd/src/Manopt.jl#L247-L257>

(when Manopt is loaded but not JuMP)

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [October 14, 2025, 9:48pm UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/12 "2025-10-14T21:48:22Z")

</div>

> It’s true that there are two errors here (no extension not loaded and wrong argument type), but one is more important than the other, and needs addressing first.

I think that error message just intends to be something like `"`render_typst_document` requires a object from an appropriate package such as Typst. Got `$(typeof(arg))` instead."`

---

<div class="post-metadata">

**Author:** ![RomeoV](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/romeov/32/37687_2.png) [@RomeoV](https://discourse.julialang.org/u/RomeoV)\
**Post date:** [October 16, 2025, 6:15am UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/13 "2025-10-16T06:15:51Z")

</div>

> [@Krastanov](#):
>
> register an error hint on method errors for the function ``

Can you elaborate what you mean by this?

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [October 16, 2025, 7:14am UTC](https://discourse.julialang.org/t/alternative-to-base-get-extension/133191/14 "2025-10-16T07:14:23Z")

</div>

My code example is exactly such an error hint registration.

If that error occurs, the hint is printed as well, giving you an idea what might resolve the problem. For functions that are only available if the extension is loaded, the hint to load the right packages is very reasonable I think.
