Introduce possibility of errors
Modulefs-sim-0.5.0.1Haskell2010
System.FS.Sim.Error
HasFS instance wrapping SimFS that generates errors, suitable for
testing error handling.
- 7 types
- 14 values
- Packagefs-sim-0.5.0.1
- Exports21
- LanguageHaskell2010
- LicenceApache-2.0
- SourceError.hs
Simulate Errors monad
4 declarationsAlternative to simErrorHasFS that creates TVars internally.
Streams
3 declarationsAn ErrorStream is a possibly infinite Stream of (Maybe)
FsErrorTypes.
Nothing indicates that there is no error.
Each time the ErrorStream is used (see runErrorStream), the first
element (Nothing in case the list is empty) is taken from the list and an
ErrorStream with the remainder of the list is returned. The first element
represents whether an error should be returned or not.
An FsError consists of a number of fields: fsErrorType, a fsErrorPath, etc. Only the first fields is interesting. Therefore, we only generate the FsErrorType. The FsErrorType will be used to construct the actual FsError.
ErrorStream for reading bytes from a file: an error or a partial get.
ErrorStream for writing bytes to a file: an error and possibly some corruption, or a partial write.
Generating partial reads/writes
4 declarationsA Partial p, where p > 0, is a number representing how many fewer
bytes should be read or written than requested.
Given a requested number of bytes to read/write, compute a partial number of bytes to read/write.
We subtract p from the number of requested bytes. If that would result in 0
requested bytes or less, we request 1 byte. If the number of requested bytes
was already 0, we can't simulate a partial read so we return 0 again.
Like partialiseByteCount, but for Word64.
Given a bytestring that is requested to be written to disk, use partialiseByteCount to compute a partial bytestring.
Blob
3 declarationsConstructors
Generating corruption for hPutSome
2 declarationsModel possible corruptions that could happen to a hPutSome call.
Constructors
SubstituteWithJunk BlobThe blob to write is substituted with corrupt junk
PartialWrite PartialOnly perform the write partially
Instances2Show, Arbitrary
Show PutCorruptionDefined in fs-sim-0.5.0.1 · System.FS.Sim.ErrorArbitrary PutCorruptionDefined in fs-sim-0.5.0.1 · System.FS.Sim.Error
Apply the PutCorruption to the ByteString.
If the bytestring is substituted by corrupt junk, then the output bytestring might be larger than the input bytestring.
Error streams for HasFS
5 declarationsError streams for the methods of the HasFS type class.
An ErrorStream is provided for each method of the HasFS type class. This ErrorStream will be used to generate potential errors that will be thrown by the corresponding method.
For hPutSome, an ErrorStreamWithCorruption is provided to simulate
corruption.
An Errors is used in conjunction with SimErrorFS, which is a layer on
top of SimFS that simulates methods throwing FsErrors.
Constructors
ErrorsdumpStateE :: ErrorStreamhOpenE :: ErrorStreamhCloseE :: ErrorStreamhSeekE :: ErrorStreamhGetSomeE :: ErrorStreamGetSomehGetSomeAtE :: ErrorStreamGetSomehPutSomeE :: ErrorStreamPutSomehTruncateE :: ErrorStreamhGetSizeE :: ErrorStreamcreateDirectoryE :: ErrorStreamcreateDirectoryIfMissingE :: ErrorStreamlistDirectoryE :: ErrorStreamdoesDirectoryExistE :: ErrorStreamdoesFileExistE :: ErrorStreamremoveDirectoryRecursiveE :: ErrorStreamremoveFileE :: ErrorStreamrenameFileE :: ErrorStreamhGetBufSomeE :: ErrorStreamGetSomehGetBufSomeAtE :: ErrorStreamGetSomehPutBufSomeE :: ErrorStreamPutSomehPutBufSomeAtE :: ErrorStreamPutSome
Return True if all streams are empty (null).
genErrors Use the given ErrorStream for each field/method. No corruption of hPutSome.