Is there a way to overload what is run for debug_show in motoko? We have an object with a member property that has a circular loop and it causes a stack overflow when trying to show it. We’d like to intercept and iterate only once through the object or skip it altogether.
AFAIK solutions have been explored for this type of thing (see below) but there isn’t a way to do it at the moment.
- Generalize debug_show/serialization to support deriving traits for mono types · Issue #1500 · dfinity/motoko · GitHub
- [Feature Idea] Contextual method modules · Issue #2537 · dfinity/motoko · GitHub
A long time ago I implemented similar things in userspace for showing, comparing, ordering, etc in Motoko but I don’t think the code is public.
I’ll follow up here with an example.