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 14 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
Copy link
Contributor

@loewenheim loewenheim left a comment

Choose a reason for hiding this comment

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

LGTM aside from a stylistic nitpick

Comment on lines 388 to +394
multipart_from_request(request, multer::Constraints::new())
.map(Self)
.map_err(Remote)
.map(|multipart| UnconstrainedMultipart {
multipart,
outcome_aggregator: state.outcome_aggregator().clone(),
request_meta,
})
.map_err(Into::into)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is clearer like this:

        let multipart = multipart_from_request(request, multer::Constraints::new())?;
        Ok(UnconstrainedMultipart {
            multipart,
            outcome_aggregator: state.outcome_aggregator().clone(),
            request_meta,
        })

(can't make a suggestion because deleted lines)

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