Skip to content

add custom error handling#20

Merged
yuvimittal merged 6 commits intoarxlang:mainfrom
yuvimittal:feature-error-handling
Nov 14, 2025
Merged

add custom error handling#20
yuvimittal merged 6 commits intoarxlang:mainfrom
yuvimittal:feature-error-handling

Conversation

@yuvimittal
Copy link
Member

Pull Request description

How to test these changes

  • ...

Pull Request checklists

This PR is a:

  • bug-fix
  • new feature
  • maintenance

About this PR:

  • it includes tests.
  • the tests are executed on CI.
  • the tests generate log file(s) (path).
  • pre-commit hooks were executed locally.
  • this PR requires a project documentation update.

Author's checklist:

  • I have reviewed the changes and it contains no misspelling.
  • The code is well commented, especially in the parts that contain more
    complexity.
  • New and old tests passed locally.

Additional information

Reviewer's checklist

Copy and paste this template for your review's note:

## Reviewer's Checklist

- [ ] I managed to reproduce the problem locally from the `main` branch
- [ ] I managed to test the new changes locally
- [ ] I confirm that the issues mentioned were fixed/resolved .

@github-actions
Copy link

OSL ChatGPT Reviewer

NOTE: This is generated by an AI program, so some comments may not make sense.

.prettierrc.yaml

LGTM!


src/arx/lexer.py

  • Potential runtime bug: constructing the message assumes location has .line/.col. If location is None or a different object, raising LexerError will itself raise AttributeError and mask the original error. Use safe access with fallbacks. Replace the body as below (L.207):

    def init(self, message: str, location: SourceLocation) -> None:
    """Initialize LexerError with an error message and optional source location."""
    line = getattr(location, "line", "?")
    col = getattr(location, "col", "?")
    super().init(f"{message} at line {line}, col {col}")
    self.location = location

  • To avoid forward-reference issues in some Python versions or when evaluating type hints at runtime, consider enabling postponed evaluation (L.1):

    from future import annotations # """Enable postponed evaluation of annotations."""


@yuvimittal yuvimittal marked this pull request as draft November 11, 2025 05:00
@yuvimittal yuvimittal marked this pull request as ready for review November 14, 2025 10:06
@github-actions
Copy link

OSL ChatGPT Reviewer

NOTE: This is generated by an AI program, so some comments may not make sense.

src/arx/lexer.py

  • Correctness: The numeric branch will treat a standalone '.' (or the start of '..') as a number, which can either mis-tokenize punctuation or raise later when converting ".". Guard the branch with a digit lookahead so only "." enters numeric lexing. Example change (L.322):
    if self.last_char.isdigit() or (self.last_char == "." and self.peek().isdigit()):
    If you don’t have peek(), add:
    def peek(self) -> str:
    """Peek next character without consuming it."""
    return self.source[self.index] if self.index < len(self.source) else "\0"

  • Breaking behavior: Introducing LexerError changes the public contract of get_token/get_next_token. Ensure callers catch this or convert it to an error token to avoid crashing the pipeline.


@yuvimittal yuvimittal merged commit 1ea560d into arxlang:main Nov 14, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants