Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt a system of exceptions derived from KaitaiStructError #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on Sep 14, 2024

  1. Configuration menu
    Copy the full SHA
    68cb21d View commit details
    Browse the repository at this point in the history

Commits on Sep 15, 2024

  1. Adopt a system of exceptions derived from KaitaiStructError

    * Resolves
      #40
    * Resolves
      #41
    
    As explained in
    #40,
    this makes it easy to handle to all errors caused by invalid input data
    by using `kaitaistruct.KaitaiStructError` in a `try..except` statement.
    Three new exception types were added: `InvalidArgumentError`,
    `EndOfStreamError` and `NoTerminatorFoundError`. All changes to raised
    exceptions in this commit should be backward compatible, as we are only
    moving to subclasses of previously raised exceptions.
    `NoTerminatorFoundError` is a subclass of `EndOfStreamError` to address
    the suggestion in
    #41.
    
    Note that the `process_rotate_left` method could only raise
    `NotImplementedError` if someone called it manually (because
    KSC-generated parsers hardcode `group_size` to `1`, see
    https://github.com/kaitai-io/kaitai_struct_compiler/blob/c23ec2ca88d84042edba76f70c1f003d062b7585/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala#L211),
    so it makes no sense to raise an exception derived `KaitaiStructError`
    (it's a programmer error, not a user input error). Most of our runtime
    libraries in other languages don't even have this `group_size`
    parameter, and if they do (C#, Java, Ruby), they also throw the
    equivalent of `NotImplementedError` (except the JavaScript runtime,
    which throws a plain string, which is _possible_ in JS but considered
    bad practice, so we should fix this).
    generalmimon committed Sep 15, 2024
    Configuration menu
    Copy the full SHA
    2a63b4f View commit details
    Browse the repository at this point in the history