Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix .throw_error() and .throw_warning() #155

Merged
merged 1 commit into from
Aug 20, 2024
Merged

Fix .throw_error() and .throw_warning() #155

merged 1 commit into from
Aug 20, 2024

Conversation

mcol
Copy link
Contributor

@mcol mcol commented Aug 20, 2024

There are two problems with the current implementation of .throw_error() and .throw_warning() which were noted in #152:

> .validate_positive_scalar(iris)
Error: [.validate_positive_scalar()] 'iris' must be a positive scalar[iris()] 'iris' must be a positive scalar
  1. The name of the caller function is not computed correctly if the caller has arguments, which messes up the output
  2. If the caller is an internal function, the internal name would be exposed to the user, rather than the name of the function the user called

This PR makes the function print the name of the calling function just once and allows using them from other internal functions, thanks to the new nframe argument that allows to control which function name is reported from the error/warning message.

When .throw_error()/.throw_warning() are called from an exported Luminescence function, one can use these two functions without worrying about nframe, they will work by default as expected. The only time that we should set nframe = 2 is when we use the throwing functions from an internal function, such as in .validate_positive_scalar().

This makes the function print the name of the calling function just once and
allows using them from other internal functions, thanks to the new nframe
argument that allows to control which function name is reported from the
error/warning message.
Copy link
Member

@RLumSK RLumSK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done, thanks!

@RLumSK RLumSK merged commit 72ebde0 into R-Lum:dev_0.9.x Aug 20, 2024
10 checks passed
@mcol mcol deleted the fix_throw_function branch August 20, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants