Skip to content

Error message - Exception has been thrown by the target of an invocation. #138

New issue

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

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

Already on GitHub? # to your account

Closed
iisfaq opened this issue Jun 3, 2022 · 3 comments
Closed
Assignees

Comments

@iisfaq
Copy link

iisfaq commented Jun 3, 2022

I was just testing your cool parser and came across the following

"Chris"[35]

This returns Exception has been thrown by the target of an invocation. - not a very friendly message.

I tracked it down to the following line


 2926                        else if (itemProperties?.Length > 0)
*2927                            return itemProperties[0].GetValue(left, oIndexingArgs.Cast<object>().ToArray()); 
 2928                        else

I changed the code to this

                            try
                            {
                                return itemProperties[0].GetValue(left, oIndexingArgs.Cast<object>().ToArray());
                            }
                            catch(Exception ex)
                            {
                                throw new Exception($"Invalid index speciifed '{string.Join(",",oIndexingArgs.Cast<object>().ToArray())}' for '{left}'");
                            }

This results in something like this

Invalid index specified '35' for 'Chris'

@iisfaq
Copy link
Author

iisfaq commented Jun 3, 2022

I was going to create a pull request but I don't think I have the rights to do that. I have not done this before.

Chris

@codingseb codingseb self-assigned this Jun 8, 2022
@codingseb
Copy link
Owner

Hello @iisfaq thanks for the issue.
Yes of course you can submit pull request. I just need to accept it to integrate your code in the main repo. (you need to fork the repo first to do you modifications and create a pull request from your repo.)

But for this issue I think I will implement a more generic solution to throw better exceptions in general with the use of ExceptionDispatchInfo as suggested by @jl0pd in #124.

codingseb added a commit that referenced this issue Jun 8, 2022
…tionContainer and TargetInvocationException (#138 and #124)
@codingseb
Copy link
Owner

I just published version 1.4.8.0 (on nuget) that should throw better exceptions in this kind of case.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants