octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modifications to error handling for the command suggestion feature


From: Sudeepam Pandey
Subject: Re: Modifications to error handling for the command suggestion feature
Date: Sun, 20 May 2018 02:42:20 +0530



On Sun, May 20, 2018 at 2:05 AM, Rik <address@hidden> wrote:
On 05/19/2018 11:46 AM, Nicholas Jankowski wrote:


On Sat, May 19, 2018, 14:02 Sudeepam Pandey <address@hidden> wrote:
All,

I'm starting to guess that adding a command suggestion feature would require some changes to the error handling.

...

Could anyone help me understand how that call could be made or maybe, help me figure out a better way to make octave first print out the 'undefined near line' error message and then tell us something about the identifier which parser did not recognize? (perhaps some better place to make the call from?)

Not any help on the code, but I'm trying to think through the under-the-hood decision tree. 

1. Unrecognized function call
2. Check for unloaded possible package function - if so suggest installing/ loading.
3. If not prompt for to-be-implemented suggestions. Since its just text display this can include a version of the error message.
4. Else: error with explanation.

Providing a list of suggestions and then returning to the CLI is going to be easier then changing the parser--which has already gone down an error path--to accept new input, backup, and re-parse the new command.  The latter can be done, but for the moment I would concentrate on just offering the user some suggestions.

You did correctly find the code in pt-id.cc to modify.  The complete routine is

  void
  tree_identifier::eval_undefined_error (void)
  {
    int l = line ();
    int c = column ();

    maybe_missing_function_hook (name ());

    if (l == -1 && c == -1)
      error_with_id ("Octave:undefined-function",
                     "'%s' undefined", name ().c_str ());
    else
      error_with_id ("Octave:undefined-function",
                     "'%s' undefined near line %d column %d",
                     name ().c_str (), l, c);
  }

What you want to do is print out an error message first, then call maybe_missing_function_hook, and then return to the prompt.  You can't use error_with_id because it is based on exceptions and will return to the prompt as soon as it is done.  However, you can print the warning to stderr, which is what the error() function is doing anyways.  Try this

Our primary need is not to print the error message first, but to make sure that an error message for the mistake made in the last command does not occur after the user has executed the correct command. 

  void
  tree_identifier::eval_undefined_error (void)
  {
    int l = line ();
    int c = column ();

    if (l == -1 && c == -1)
      std::cerr << "'" << name () << "' undefined\n";
    else
      std::cerr << "'" << name () << "' undefined near "
                << "line " << l << " column " << c << "\n";

    maybe_missing_function_hook (name ());

    error_with_id ("Octave:undefined-function", "");
  }


I think you need to leave some error condition as a final fallback to terminate execution. I don't know if you can call the the error message early before terminating execution. Maybe that's what you're suggesting?

This brings up another thought: if I make a typo in a script, do I want command suggestion to occur? I don't think so. If we mess with general error handling, can that be aware of whether the typo happened at the CLI?


I agree.  At least in C++ you can check whether you are at the top-level scope, i.e., the command line.  There is probably a way to do so within Octave, jwe might know of a particular variable to check.

--Rik





reply via email to

[Prev in Thread] Current Thread [Next in Thread]