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

Initial implementation of a safe (no fatalErrors thrown) OutputStream. #75

Merged
merged 3 commits into from Jan 19, 2019

Conversation

tonystone
Copy link
Owner

@tonystone tonystone commented Jan 16, 2019

The current implementation (as of this writing) of FileHandle in swift will call fatalError() for any thrown error during the write operation.

    public func write(_ data: Data) {
        data.enumerateBytes() { (bytes, range, stop) in
            do {
                try NSData.writeToFileDescriptor(self._fd, path: nil, buf: UnsafePointer<Void>(bytes.baseAddress!), length: bytes.count)
            } catch {
                fatalError("Write failure")
            }
        }
    }

TraceLog must be reliable and not have cases that will crash the app so we were compelled to write our own FileOutputStream class to replace the FileHandle foundation class. This also gives us the advantage of improved performance during writes.

See: https://bugs.swift.org/browse/SR-2138 for more information.

@codecov
Copy link

codecov bot commented Jan 16, 2019

Codecov Report

Merging #75 into release-5.0 will decrease coverage by 0.25%.
The diff coverage is 96.42%.

@@               Coverage Diff               @@
##           release-5.0      #75      +/-   ##
===============================================
- Coverage        99.13%   98.88%   -0.26%     
===============================================
  Files               22       23       +1     
  Lines              578      625      +47     
===============================================
+ Hits               573      618      +45     
- Misses               5        7       +2
Impacted Files Coverage Δ
.../TraceLog/Utilities/Streams/FileOutputStream.swift 100% <100%> (ø)
Sources/TraceLog/Writers/FileWriter.swift 100% <100%> (ø) ⬆️
Sources/TraceLog/Writers/ConsoleWriter.swift 100% <100%> (ø) ⬆️
...es/TraceLog/Utilities/Streams/StandardStream.swift 50% <50%> (ø)

@codecov
Copy link

codecov bot commented Jan 16, 2019

Codecov Report

Merging #75 into release-5.0 will increase coverage by 0.86%.
The diff coverage is 100%.

@@              Coverage Diff              @@
##           release-5.0    #75      +/-   ##
=============================================
+ Coverage        99.13%   100%   +0.86%     
=============================================
  Files               22     26       +4     
  Lines              578    711     +133     
=============================================
+ Hits               573    711     +138     
+ Misses               5      0       -5
Impacted Files Coverage Δ
.../TraceLog/Utilities/Streams/FileOutputStream.swift 100% <100%> (ø)
...es/TraceLog/Utilities/Streams/StandardStream.swift 100% <100%> (ø)
...og/Utilities/Streams/OutputStreamError+Posix.swift 100% <100%> (ø)
Sources/TraceLog/Writers/ConsoleWriter.swift 100% <100%> (ø) ⬆️
...tilities/Streams/FileOutputStreamError+Posix.swift 100% <100%> (ø)
Sources/TraceLog/Writers/FileWriter.swift 100% <100%> (ø) ⬆️
... and 3 more

@tonystone tonystone changed the title Initial implementation of a safe (no fatelerrors thrown) OutputStream. Initial implementation of a safe (no fatalErrors thrown) OutputStream. Jan 19, 2019
@tonystone tonystone merged commit 04cccbe into release-5.0 Jan 19, 2019
@tonystone tonystone deleted the safe-stream branch January 19, 2019 19:03
tonystone added a commit that referenced this pull request Jan 19, 2019
…ering

* 'release-5.0' of github.com:tonystone/tracelog:
  Implement exception free streams for writing to files and the console. (#75)

# Resolved Conflicts:
#	Sources/TraceLog/Internal/Utilities/FileHandle+OutputStream.swift
#	Sources/TraceLog/Internal/Utilities/OutputStream.swift
#	Sources/TraceLog/Utilities/FileHandle+OutputStream.swift
#	Sources/TraceLog/Writers & Formatters/ConsoleWriter.swift
#	Sources/TraceLog/Writers & Formatters/FileWriter.swift
#	Tests/TraceLogTests/Utilities/Streams/StandardStreamTests.swift
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.

None yet

1 participant