-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
Could I throw an error in script for anko to catch and return it to caller #338
Comments
Sure. Run or RunContext return an error. Or maybe return a variable on what files are incorrect. There are lots of options. |
Thanks, Michael @MichaelS11 Anko is really cool for Go programmers |
@MichaelS11 Thanks for your help on this awesome project. I was wondering if you could provide an example of how to use Run or RunContext to implement a stack trace of sorts? for example, let's say we had a defined function called
What would be your recommendation for avoiding checking for errors inline (like in the psuedo script above), as a 2nd return value (like go does), and implementing something similar to a Python exception. If the error occurred, and was not caught, then it would exit, with some stack trace. But if the error was caught, then it could be handled, and the script could continue to run. Again, thanks for the awesome project. Just looking for a little guidance / recommendation on how to implement something like this. |
Most welcome :) Why do you want a stack trace? What would you use it for? You could also use https://golang.org/pkg/runtime/debug/#Stack without throwing an exception. I have a feeling there is probably a better way. Maybe a return variable or a custom error. Need more information. I would tend to stick with the |
So, in my particular use case I am writing an automation language called Orcascript. I am using anko as the foundation, and providing a suite of libraries that should "just work" out of the box for a lot of common devops/sre automation tasks. I have some other tools that would be used in conjunction with Orcascript once I have it in stable form. A lot of the potential users of such a tool would be coming from a Python/Ansible background and would be familiar with the workflow that I described above. And when you are dealing with task automation, using custom functions, etc, there are a lot of things that could fail, so seeing the stacktrace of what failed, and where, would be very useful in resolving any scripting related errors. So, in the psuedo example I gave, a python error may look like this:
And optionally, I could catch the error, and handle it accordingly. I would like for my users to (optionally) check for an error in Orcascript (anko) in a similar way, and if the error exist, and isn't handled, provide some form of stacktrace / error message. Hopefully that helps provide some context for my particular use case. |
Error message is easy enough. Should be able to work that out with Anko. Plus Anko errors do have location information. They might have some kind of additional stack trace type information hidden in them but have not spend any time seeing if that is the case or not. Also because you are using layers on top of layers of code, might need to build a stack trace. Maybe this might give you some ideas: Additionally depending on what you are doing, Anko might not have what you need in its current state. There has been talk about updating Anko error handling ("stack trace") but have not seen anyone spending any time on it and I will not have time to spend on Anko coding in the foreseeable future. Hope that helps guide you in the right direction. |
Ok, Thanks for your help! Much appreciated. |
We use anko as script to process files dynamically in our golang project.
Sometimes the file's format is incorrect, such as missing some necessary fields.
Could I throw an error in script? And then anko can catch and return the error to caller
Thanks.
The text was updated successfully, but these errors were encountered: