Skip to content

feat(playstation): Emit outcome for skipped fields #4862

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

tobias-wilfert
Copy link
Member

@tobias-wilfert tobias-wilfert commented Jun 25, 2025

Currently there is no communication to the user about a field being skipped. This PR adds the logic for emitting outcomes for skipped fields such that the users are aware of these skipped fields.

Follow up to: #4793

Comment on lines +181 to +192
impl IntoResponse for BadMultipart {
fn into_response(self) -> Response {
let status_code = match self {
BadMultipart::Multipart(
multer::Error::FieldSizeExceeded { .. } | multer::Error::StreamSizeExceeded { .. },
) => StatusCode::PAYLOAD_TOO_LARGE,
_ => StatusCode::BAD_REQUEST,
};

(status_code, ApiErrorResponse::from_error(&self)).into_response()
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This copies the behaviour found here:

fn into_response(self) -> Response {
let Self(ref error) = self;
let status_code = match error {
multer::Error::FieldSizeExceeded { .. } => StatusCode::PAYLOAD_TOO_LARGE,
multer::Error::StreamSizeExceeded { .. } => StatusCode::PAYLOAD_TOO_LARGE,
_ => StatusCode::BAD_REQUEST,
};
(status_code, ApiErrorResponse::from_error(error)).into_response()

@@ -177,7 +215,10 @@ where
let content_type = field.content_type().cloned();
let field = LimitedField::new(field, config.max_attachment_size());
match field.bytes().await {
Err(multer::Error::FieldSizeExceeded { .. }) if ignore_large_fields => continue,
Err(multer::Error::FieldSizeExceeded { limit, .. }) if ignore_large_fields => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheating here a bit by putting the consumed size into the error rather than the limit that is breached such that we can use that value to generate the outcome.

Comment on lines +408 to +420
|quantity| {
outcome_aggregator.send(TrackOutcome {
timestamp: request_meta.received_at(),
scoping: request_meta.get_partial_scoping(),
outcome: Outcome::Invalid(DiscardReason::TooLarge(
DiscardItemType::Attachment(DiscardAttachmentType::Attachment),
)),
event_id: None,
remote_addr: request_meta.remote_addr(),
category: DataCategory::Attachment,
quantity,
})
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried making this a method of UnconstrainedMultipart but that did not work since we also need the self.multiparts when invoking multipart_items hence it is like this.

@tobias-wilfert tobias-wilfert self-assigned this Jun 25, 2025
@tobias-wilfert tobias-wilfert marked this pull request as ready for review June 26, 2025 06:34
@tobias-wilfert tobias-wilfert requested a review from a team as a code owner June 26, 2025 06:34
config: &Config,
ignore_large_fields: bool,
) -> Result<Items, multer::Error>
where
F: FnMut(Option<&str>, &str) -> AttachmentType,
G: FnMut(u32),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest making this an FnMut(Outcome, u32) and generating the Outcome::Invalid(DiscardReason::TooLarge(…)) outcome in the if ignore_large_fields branch below (and don't pass it in UnconstrainedMultipart::items).

The reason is admittedly kind of aesthetic—here you have a function called emit_outcome that only handles u32 values.

Comment on lines +368 to +370
pub multipart: Multipart<'static>,
pub outcome_aggregator: Addr<TrackOutcome>,
pub request_meta: RequestMeta,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fields probably shouldn't be public, this is now implementation detail territory, if you need access to the multipart, I'd just add a into_multipart() or From impl instead.

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.

3 participants