Skip to content

Commit dafba92

Browse files
committed
rename error states from code review
1 parent be2e93a commit dafba92

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

stdlib/public/Darwin/Compression/Compression.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public enum FilterError: Error {
4444
/// Filter failed to initialize,
4545
/// invalid internal state,
4646
/// invalid parameters
47-
case state
47+
case invalidState
4848

4949
/// Invalid data in a call to compression_stream_process,
5050
/// non-empty write after an output filter has been finalized
51-
case data
51+
case invalidData
5252
}
5353

5454
/// Compression filter direction of operation, compress/decompress
@@ -75,7 +75,7 @@ extension compression_stream {
7575
/// - Parameter operation: direction of operation
7676
/// - Parameter algorithm: compression algorithm
7777
///
78-
/// - Throws: `FilterError.state` if `algorithm` is not supported
78+
/// - Throws: `FilterError.invalidState` if `algorithm` is not supported
7979
/// by the Compression stream API
8080
///
8181
internal init(operation: FilterOperation, algorithm: Algorithm) throws {
@@ -85,7 +85,7 @@ extension compression_stream {
8585
src_size: 0,
8686
state: nil)
8787
let status = compression_stream_init(&self, operation.rawValue, algorithm.rawValue)
88-
guard status == COMPRESSION_STATUS_OK else { throw FilterError.state }
88+
guard status == COMPRESSION_STATUS_OK else { throw FilterError.invalidState }
8989
}
9090
}
9191

@@ -105,7 +105,7 @@ public class OutputFilter {
105105
/// - bufferCapacity: capacity of the internal data buffer
106106
/// - writeFunc: called to write the processed data
107107
///
108-
/// - Throws: `FilterError.state` if stream initialization failed
108+
/// - Throws: `FilterError.invalidState` if stream initialization failed
109109
public init(
110110
_ operation: FilterOperation,
111111
using algorithm: Algorithm,
@@ -127,14 +127,14 @@ public class OutputFilter {
127127
/// - Parameter data: data to process
128128
///
129129
/// - Throws:
130-
/// `FilterError.data` if an error occurs during processing,
130+
/// `FilterError.invalidData` if an error occurs during processing,
131131
/// or if `data` is not empty/nil, and the filter is the finalized state
132132
public func write<D : DataProtocol>(_ data: D?) throws {
133133
// Finalize if data is empty/nil
134134
if data == nil || data!.isEmpty { try finalize() ; return }
135135

136136
// Fail if already finalized
137-
if _finalized { throw FilterError.data }
137+
if _finalized { throw FilterError.invalidData }
138138

139139
// Process all incoming data
140140
for region in data!.regions {
@@ -152,7 +152,7 @@ public class OutputFilter {
152152
/// When all output has been sent, the writingTo closure is called one last time with nil data.
153153
/// Once the stream is finalized, writing non empty/nil data to the stream will throw an exception.
154154
///
155-
/// - Throws: `FilterError.data` if an error occurs during processing
155+
/// - Throws: `FilterError.invalidData` if an error occurs during processing
156156
public func finalize() throws {
157157
// Do nothing if already finalized
158158
if _finalized { return }
@@ -187,7 +187,7 @@ public class OutputFilter {
187187
_stream.dst_size = _bufCapacity
188188

189189
let status = compression_stream_process(&_stream, (finalize ? Int32(COMPRESSION_STREAM_FINALIZE.rawValue) : 0))
190-
guard status != COMPRESSION_STATUS_ERROR else { throw FilterError.data }
190+
guard status != COMPRESSION_STATUS_ERROR else { throw FilterError.invalidData }
191191

192192
// Number of bytes written to buf
193193
let writtenBytes = _bufCapacity - _stream.dst_size
@@ -245,7 +245,7 @@ public class InputFilter<D: DataProtocol> {
245245
public func advance(by n: Int) throws {
246246

247247
// Sanity checks
248-
if n > _regionRemaining { throw FilterError.state } // invalid n
248+
if n > _regionRemaining { throw FilterError.invalidState } // invalid n
249249

250250
// Update counters
251251
_regionRemaining -= n
@@ -260,7 +260,7 @@ public class InputFilter<D: DataProtocol> {
260260
}
261261

262262
// Sanity checks
263-
if _remaining != 0 && _regionRemaining == 0 { throw FilterError.state }
263+
if _remaining != 0 && _regionRemaining == 0 { throw FilterError.invalidState }
264264
}
265265
}
266266

@@ -279,7 +279,7 @@ public class InputFilter<D: DataProtocol> {
279279
/// - bufferCapacity: capacity of the internal data buffer
280280
/// - readFunc: called to read the input data
281281
///
282-
/// - Throws: `FilterError.state` if filter initialization failed
282+
/// - Throws: `FilterError.invalidState` if filter initialization failed
283283
public init(
284284
_ operation: FilterOperation,
285285
using algorithm: Algorithm,
@@ -303,7 +303,7 @@ public class InputFilter<D: DataProtocol> {
303303
/// - Returns: a new Data object containing at most `count` output bytes, or nil if no more data is available
304304
///
305305
/// - Throws:
306-
/// `FilterError.data` if an error occurs during processing
306+
/// `FilterError.invalidData` if an error occurs during processing
307307
public func readData(ofLength count: Int) throws -> Data? {
308308
// Sanity check
309309
precondition(count > 0, "number of bytes to read can't be 0")
@@ -340,7 +340,7 @@ public class InputFilter<D: DataProtocol> {
340340
_stream.src_ptr = src_buf.baseAddress!.assumingMemoryBound(to: UInt8.self)
341341
_stream.src_size = src_buf.count
342342
let status = compression_stream_process(&_stream, (_eofReached ? Int32(COMPRESSION_STREAM_FINALIZE.rawValue) : 0))
343-
guard status != COMPRESSION_STATUS_ERROR else { throw FilterError.data }
343+
guard status != COMPRESSION_STATUS_ERROR else { throw FilterError.invalidData }
344344
if status == COMPRESSION_STATUS_END { _endReached = true }
345345
// Advance by the number of consumed bytes
346346
let consumed = src_buf.count - _stream.src_size
@@ -349,7 +349,7 @@ public class InputFilter<D: DataProtocol> {
349349
} else {
350350
// No data available, process until END reached
351351
let status = compression_stream_process(&_stream, (_eofReached ? Int32(COMPRESSION_STREAM_FINALIZE.rawValue) : 0))
352-
guard status != COMPRESSION_STATUS_ERROR else { throw FilterError.data }
352+
guard status != COMPRESSION_STATUS_ERROR else { throw FilterError.invalidData }
353353
if status == COMPRESSION_STATUS_END { _endReached = true }
354354
}
355355

0 commit comments

Comments
 (0)