How can I throw a user-friendly error that does not point to the code that fails?

For my abbreviations functionality I’d like to halt compilation when an abbreviation is detected that is not available in the global dictionary. I do this with an assert:

#assert(abbr in GLOBALDICT.keys(), message: "

!!!!!!!!! ABBREVIATION MISSING !!!!!!!!!!

The abbreviation " + abbr + " does not exist in the abbreviation dictionary.

")

The problem is that the user sees redundant information when they forget to supply an abbreviation:

[typst]: Compiling scratch.typ to scratch.pdf...error: assertion failed: 

!!!!!!!!! ABBREVIATION MISSING !!!!!!!!!!

The abbreviation CTROUGHT does not exist in the abbreviation dictionary.


    ┌─ scratch/scratch.typ:352:0
    │  
352 │ ╭ assert(abbr in GLOBALDICT.keys(), message: "
353 │ │ 
354 │ │ !!!!!!!!! ABBREVIATION MISSING !!!!!!!!!!
355 │ │ 
356 │ │ The abbreviation " + abbr + " does not exist in the abbreviation dictionary.
357 │ │ 
358 │ │ ")
    │ ╰──^

For the user, it really does not matter in what function the assert is triggered, they should just see the notice. Is that possible in Typst?

I don’t think there is any useful facility in Typst for now that helps with that. Best I could manage with Typst is to use panic instead.

watching test.typ
writing to test.pdf

[15:45:23] compiled with errors

error: panicked with: "glossarium@0.5.6 error : glossary is empty. Use `register-glossary(entry-list)` immediately after `make-glossary`."
     ┌─ @preview/glossarium:0.5.6/themes/default.typ:1131:8
     │
1131 │         panic(__error_message(none, __glossary_is_empty))
     │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Thanks, I had also found panic but it has the same problem. I might open an issue as stopping a render without it looking like a bug would be a good feature I think.

Since this is a package, this seems relevant: Support for emitting custom warnings · Issue #1322 · typst/typst · GitHub, Logging function for debug output · Issue #1669 · typst/typst · GitHub. As an author of your own thing, I wouldn’t care about double output, this also happens in Python and probably somewhere else. So making this for non-package errors seems unnecessary. And package-related stuff is discussed in those issues.