Feature #995

Handle errors more gracefully

Added by yexo over 9 years ago. Updated over 8 years ago.

Status:ClosedStart date:2010-07-05
Priority:NormalDue date:
Assignee:-% Done:

100%

Category:-
Target version:-

Description

In output_grf.py there are a couple "raise some_string" lines, those should be replaced by some error class. ScriptError could be used, but perhaps a new class would be better.

nml/nml.py should catch ScriptError and just display the message or something like that, currently a complete stacktrace is shown every time which is good for debugging but not for a user.

get_position.patch Magnifier - replace LexToken class by ScannerToken class to add get_position() (323 Bytes) Alberth, 2010-06-09 22:31


Subtasks

Bug #1077: internal error, assertion of byte valueClosed

Associated revisions

Revision 542:1e75dcb22941
Added by Alberth over 9 years ago

Feature: Report warnings for strings not defined in the default language (refs #995).

Revision 542:1e75dcb22941
Added by Alberth over 9 years ago

Feature: Report warnings for strings not defined in the default language (refs #995).

Revision 544:e607e39c3ede
Added by Alberth over 9 years ago

Fix: Generate a nicer error message for unfindable strings (refs #995).

Revision 544:e607e39c3ede
Added by Alberth over 9 years ago

Fix: Generate a nicer error message for unfindable strings (refs #995).

History

#1 Updated by Alberth over 9 years ago

One thing that should be fixed (first?) is adding some form of position information to the exceptions, so a user has a clue where to look for fixing the error. The current stack trace may be ugly, but it gives some information where the program fails.

I'd like to propose to extend the *Error classes (from a common base class?) with a 'position' field.

That position should be pulled from a scanner token, not by getting token.lineno, but by something like in the attached patch (against Ply 3.3).
It changes the LexToken objects produced by the lexer to ScannerToken objects, from which you can call get_position().
(This is quite hacky. For safety, we may want to distribute the lex.py as part of the nml package. I just sent a patch to do this in a nicer way upstream.)

The reason for doing it this way, is to allow adding of a filename as requested in some other issue.

#2 Updated by yexo over 9 years ago

This will be difficult when an error occurs on a reduced expression, or should reduce try to retain the position of elements?

#3 Updated by Alberth over 9 years ago

In a compiler at work, I used intervals of a file (line 3, column 5 to line 18, column 31).
Just keeping track of start/end line numbers would be sufficient too for most cases.

In theory, an interval can cross file boundaries, but that may be rare enough not to bother about.

Computing an interval with a reduction it is not complicated. When reducing an operator, ask the start position of the first operand, and the end position of the last. That is the new interval.

#4 Updated by yexo over 9 years ago

So then we'd need to implement #969 first and add some more information to the Position class. (begin/end column, and last line).

#5 Updated by yexo over 9 years ago

  • Target version set to 0.1.0

#6 Updated by yexo over 9 years ago

  • Target version deleted (0.1.0)

Still needs some checking, but it's good enough for 0.1

#7 Updated by planetmaker over 9 years ago

The error message when the default.lng file is missing is quite mis-leading:
NML: String "STR_GRF_NAME" is not translatable

#8 Updated by yexo over 9 years ago

That part of the code needs more warnings/errors anyway, I think translating a string that is not in default.lng should give a warning too.

#9 Updated by Hirundo over 8 years ago

  • Status changed from New to Closed

Also available in: Atom PDF