-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Make MultipartParserError Public #112
Open
nakul-py
wants to merge
14
commits into
vapor:main
Choose a base branch
from
nakul-py:multipartparsererror
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+60
−4
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
91d8b31
feat: Make MultipartParserError public
nakul-py 1ccc071
feat: Make MultipartParserError public like JWT
nakul-py 65e35a6
feat: Make MultipartParserError public like JWT
nakul-py 23b5969
feat: Make MultipartParserError public like JWT
nakul-py e7bcb2a
feat: Making MultipartParserError public like JWT
nakul-py 48bb25d
Update Sources/MultipartKit/MultipartParserError.swift
nakul-py 2511adf
Update Sources/MultipartKit/MultipartParserError.swift
nakul-py 52d1a34
feat: Making MultipartParserError public
nakul-py eeb50cd
Merge branch 'multipartparsererror' of https://github.com/nakul-py/mu…
nakul-py 733593d
Making MultipartParserError public
nakul-py be2b7e2
feat: Make MultipartParserError public
nakul-py c72b0fa
feat: Make MultipartParserError public
nakul-py 11759ec
MultipartParserError message with reason
nakul-py d81511e
feat: Making MultipleParserError public
nakul-py File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,63 @@ | ||
/// Technical parsing error, such as malformed data or invalid characters. | ||
/// This is mainly used by ``MultipartParser``. | ||
package enum MultipartParserError: Swift.Error, Equatable { | ||
case invalidBoundary | ||
case invalidHeader(reason: String) | ||
case invalidBody(reason: String) | ||
public struct MultipartParserError: Swift.Error, Equatable, Sendable { | ||
public struct ErrorType: Equatable, CustomStringConvertible { | ||
enum Base: String, Equatable { | ||
case invalidBoundary | ||
case invalidHeader | ||
case invalidBody | ||
} | ||
|
||
let base: Base | ||
|
||
private init(_ base: Base) { | ||
self.base = base | ||
} | ||
|
||
public static let invalidBoundary = Self(.invalidBoundary) | ||
public static let invalidHeader = Self(.invalidHeader) | ||
public static let invalidBody = Self(.invalidBody) | ||
|
||
public var description: String { | ||
base.rawValue | ||
} | ||
} | ||
|
||
private struct Backing: Equatable, Sendable { | ||
let errorType: ErrorType | ||
let reason: String? | ||
} | ||
|
||
private var backing: Backing | ||
|
||
public var errorType: ErrorType { backing.errorType } | ||
public var reason: String? { backing.reason } | ||
|
||
private init(backing: Backing) { | ||
self.backing = backing | ||
} | ||
|
||
private init(errorType: ErrorType) { | ||
self.backing = .init(errorType: errorType, reason: nil) | ||
} | ||
|
||
public static let invalidBoundary = Self(errorType: .invalidBoundary) | ||
|
||
public static func invalidHeader(reason: String) -> Self { | ||
.init(backing: .init(errorType: .invalidHeader, reason: reason)) | ||
} | ||
|
||
public static func invalidBody(reason: String) -> Self { | ||
.init(backing: .init(errorType: .invalidBody, reason: reason)) | ||
} | ||
|
||
public var description: String { | ||
if let reason = reason { | ||
return "MultipartParserError(errorType: \(errorType), reason: \(reason))" | ||
} else { | ||
return "MultipartParserError(errorType: \(errorType))" | ||
} | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you need the Backing type. What is this giving us over just adding the following to MultipartParserError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use the Backing type because it provides a single place to modify error-related data without exposing too much detail in MultipartParserError.
And If we later want to add more fields (e.g., identifier, underlyingError, or HTTPStatusCode), we can do so without cluttering the main struct.
@adam-fowler will you in the favour of remove Backing type.