question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EvForm tracebacks with certain dissimilar line lengths of form

See original GitHub issue

Brief summary of issue / Description of requested feature:

EvForm throws an exception, apparently if the form has a shorter line following a line with a cell.

In addition, the EvForm documentation reports that "CELLCHAR" is the key name to use for the inline dict, but it is actually "FORMCHAR" which provides the functionality.

Steps to reproduce the issue / Reasons for adding feature:

from evennia.utils.evform import EvForm

TEST_A = """
Test form: xx1xx
Won't crash?
"""

TEST_B = """
Test form: xx1xx
Crashhhhhh.
"""

TEST_A_FORM = {"FORMCHAR": "x", "TABLECHAR": "c", "FORM": TEST_A}
TEST_B_FORM = {"FORMCHAR": "x", "TABLECHAR": "c", "FORM": TEST_B}

form_a = EvForm(form=TEST_A_FORM, cells={1: 'hello'})
self.msg(form_a)

form_b = EvForm(form=TEST_B_FORM, cells={1: 'hello'})
self.msg(form_b)

Error output / Expected result of feature

File "evennia/utils/evform.py", line 215, in __init__
  self.reload()
File "evennia/utils/evform.py", line 418, in reload
  self.mapping = self._parse_rectangles(self.cellchar, self.tablechar, self.raw_form, **kwargs)
File "evennia/utils/evform.py", line 276, in _parse_rectangles
  if all(form[iy + i][ix] == cellchar for ix in range(leftix, rightix)):
File "evennia/utils/evform.py", line 276, in 
  if all(form[iy + i][ix] == cellchar for ix in range(leftix, rightix)):
File "evennia/utils/ansi.py", line 888, in __getitem__
  raise IndexError("ANSIString Index out of range")
IndexError: ANSIString Index out of range

Extra information, such as Evennia revision/repo/branch, operating system and ideas for how to solve / implement:

Evennia 0.7.0 (rev 2bc76538)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Henddhercommented, Aug 21, 2018

Hello all,

After a “quick” look with pdb, I arrived to the following:

The issue happens in line 312 when form is accessed with the indices obtained from matching the first xxNxx row.
https://github.com/evennia/evennia/blob/a53957096f33ce991a52921fe9a26e1984367ede/evennia/utils/evform.py#L308-L315

It seems like a form object is always expected to be a rectangle. See line 410. In @RyanStein’s test form, that’s not the case.

https://github.com/evennia/evennia/blob/a53957096f33ce991a52921fe9a26e1984367ede/evennia/utils/evform.py#L410-L411

I’m thinking that the following could do the trick:

        # split into a list of list of lines. Form can be indexed with form[iy][ix]
        self.raw_form = _to_ansi(to_unicode(datadict.get("FORM", "")).split("\n"))
        _rectangularize(self.raw_form)
       ...

The _rectangularize function calculates the longest line and forces all lines to be of that max length, effectively converting the jagged form into a rect.

WDYT @Griatch?

0reactions
Griatchcommented, Sep 13, 2018

Closed with merge of PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coding Utils · evennia/evennia Wiki - GitHub
This function will crop a very long line, adding a suffix to show the line actually continues. This can be useful in listings...
Read more >
CS697 Class Notes - UMass Boston CS
that these sequences have different lengths – this is not uncommon for protien sequences. A common approach to judging similarity is to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found