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

Replace all String-based error messages with structured error types #37

Open
6 tasks
RyanGlScott opened this issue Feb 20, 2023 · 0 comments
Open
6 tasks

Comments

@RyanGlScott
Copy link
Contributor

Generally speaking, elf-edit adheres to the convention of using structured data types to represent its error messages, such as with the DynamicError data type. Unfortunately, there are still some parts of elf-edit that use raw Strings to represent errors:

  • -- | Parses a linked list
    gnuLinkedList :: (B.ByteString -> Get a) -- ^ Function for reading.
    -> ElfData
    -> Int -- ^ Number of entries expected.
    -> B.ByteString -- ^ Buffer to read.
    -> Either String [a]
  • -- | Get values of DT_NEEDED entries
    dynNeeded :: forall w . DynamicSection w -> VirtAddrMap w -> Either String [B.ByteString]
  • -- | Attempt to convert a section to a GOT.
    elfSectionAsGOT :: (Bits w, Num w)
    => ElfSection w
    -> Either String (ElfGOT w)
  • transShdr :: Integral w
    => B.ByteString -- ^ Contents fof file.
    -> B.ByteString -- ^ String table for sectionnames
    -> Word16 -- ^ Index of section
    -> Shdr Word32 w
    -> Either String (FileRange w, ElfSection w)
  • -- | Return relocation entries from byte string.
    decodeRelEntries :: forall tp
    . IsRelocationType tp
    => ElfData -- ^ Endianess of encodings
    -> B.ByteString -- ^ Relocation entries
    -> Either String [RelEntry tp]
  • -- | Return relocation entries from byte string.
    decodeRelaEntries :: forall tp
    . IsRelocationType tp
    => ElfData -- ^ Endianess of encodings
    -> B.ByteString -- ^ Relocation entries
    -> Either String [RelaEntry tp]

We should replace these uses of Either String with Either <structured error type>, where the specific structured error type is specific to the function in question. We might be able to use existing error types for some functions; for instance, dynNeeded could likely use Either DynamicError, just like other functions in Data.ElfEdit.Dynamic do.

I don't have a pressing need to fix this right now, especially since fixing this would require API changes. This does seem like a goal that we should work towards in the long term, however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant