Comments (7)
Thanks, Michael @MichaelS11
Anko is really cool for Go programmers
from anko.
Ok, Thanks for your help! Much appreciated.
from anko.
Sure. Run or RunContext return an error. Or maybe return a variable on what files are incorrect. There are lots of options.
from anko.
@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 read
in the environment. Then, in our script we had something like this:
text, err = read("sometext.txt")
if err != nil {
// we were unable to read the file for some reason...
}
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.
from anko.
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 blah, err = foo()
then check error format unless there is no other way.
from anko.
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:
Traceback (most recent call last):
File "test.py", line 2, in <module>
with open("file.txt") as f:
IOError: [Errno 2] No such file or directory: 'file.txt'
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.
Thanks for the fast response!
from anko.
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:
https://dave.cheney.net/2016/06/12/stack-traces-and-the-errors-package
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.
from anko.
Related Issues (20)
- Execute function instead of whole script HOT 6
- Master branch doesn't follow releases HOT 14
- dangerous packages import HOT 10
- goroutine crash silently HOT 14
- Cannot use vm in multiple goroutines HOT 3
- Method overriding in custom structs HOT 11
- unknown field 'Structs' in struct literal of type ast.TypeStruct HOT 9
- Anon calls doesn't report the expr position HOT 4
- Crashed by invalid input
- question: extending slices and getting data out HOT 1
- Can a function be created
- when "new" and "make" structure, field will not be zero value.
- Playground (http://play-anko.appspot.com/) returns 500 HOT 5
- undefined symbol 'Atoi' HOT 1
- Methods definition
- How can I get the result HOT 5
- How to check if a channel is closed? HOT 1
- Data race when running scripts concurrently HOT 3
- Mathematical expression computation bug HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anko.