Skip to content

source location is not available in some important run-time errors #15

Description

@GrahamAsher

I have been trying to add informative error messages to my code that uses TeaScript and have run into a problem that makes it much harder for users to debug their code. The problem occurs both when interpreting the code and when running compiled code. The code is syntactically correct and compilation is successful.

In this relatively short piece of code there is an error:

            {
            def power := input("power")
            if (power is String)
                {
                if (power == "line" or power == "minor_line")
                    {
                    copy("_","voltage")
                    copy("_","ref")
                    if (input("layer") > 0)
                        { set_level(input("layer") + 1) }
                    }
                def height := input("height")
                if (height is String)
                    { set("_t",height) }
                if (power == "line") { commit("power/major","pwl",LINE) }
                else if (power == "tower") { commit("power/major","pwt",POINT) }
                else if (power == "minor_line") { commit("power/minor","mpl",LINE) }
                else if (power == "pole") { commit("power/minor","pwp",LINE) }
                else if (power == "substation") { commit("power/minor","pss",if (is_osm_node) { POINT } else { POLYGON }) }
                }
            }

It's not at all obvious. The error is that is_osm_node is a function, not a boolean variable, so a runtime exception is thrown at line 960 of ValueObject.cpp:

            []( auto ) -> bool { throw exception::bad_value_cast("ValueObject not convertible to bool!"); },

Imagine going through hundreds of lines of code trying to find out why it happened. Not a pleasant prospect.

The solution is for the interpreter to trap the exception and add location information (line and column number) to it, then re-throw. Execution of a compiled program cannot and need not do that; users can run their programs in the interpreter to find an error. Indeed, I tried doing that. In my error handler for compiled programs I retried running the program's source code in the interpreter to see if it would yield more useful information, but to no avail. Hence this report.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions