• Daniel Martí's avatar
    blockstore: use errors when API contracts are broken · a6dc547f
    Daniel Martí authored
    It's technically correct to use panics in these situations,
    as the downstream user is clearly breaking the contract documented in
    the API's godoc.
    
    However, all these methods return errors already,
    so panicking is not our only option here.
    
    There's another reason that makes a panic unfortunate.
    ReadWrite.Finalize enables the panic behavior on other methods,
    which makes it much easier to run into in production
    even when the code and its tests work normally.
    
    Finally, there's some precedent for IO interfaces using errors rather
    than panics when they are used after closing.
    For example, os.File.Read returns an error if the file is closed.
    
    Note that this change doesn't make panics entirely impossible.
    The blockstore could still run into exceptional and unexpected panics,
    such as those caused by memory corruption or internal bugs.
    a6dc547f
readonly.go 11.9 KB