Code Monkey home page Code Monkey logo

Comments (7)

borgerli avatar borgerli commented on August 23, 2024 1

Thanks, Michael @MichaelS11

Anko is really cool for Go programmers

from anko.

dsikes avatar dsikes commented on August 23, 2024 1

Ok, Thanks for your help! Much appreciated.

from anko.

MichaelS11 avatar MichaelS11 commented on August 23, 2024

Sure. Run or RunContext return an error. Or maybe return a variable on what files are incorrect. There are lots of options.

from anko.

dsikes avatar dsikes commented on August 23, 2024

@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.

MichaelS11 avatar MichaelS11 commented on August 23, 2024

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.

dsikes avatar dsikes commented on August 23, 2024

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.

MichaelS11 avatar MichaelS11 commented on August 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.