@@ -283,7 +283,7 @@ impl Processor for TrimmingProcessor {
283
283
}
284
284
285
285
processor:: apply ( & mut stacktrace. frames , |frames, meta| {
286
- enforce_frame_hard_limit ( frames, meta, 250 ) ;
286
+ enforce_frame_hard_limit ( frames, meta, 200 , 50 ) ;
287
287
Ok ( ( ) )
288
288
} ) ?;
289
289
@@ -359,12 +359,26 @@ fn trim_string(value: &mut String, meta: &mut Meta, max_chars: usize, max_chars_
359
359
} ) ;
360
360
}
361
361
362
- fn enforce_frame_hard_limit ( frames : & mut Array < Frame > , meta : & mut Meta , limit : usize ) {
363
- // Trim down the frame list to a hard limit. Prioritize the last frames.
362
+ /// Trim down the frame list to a hard limit.
363
+ ///
364
+ /// The total limit is `recent_frames` + `old_frames`.
365
+ /// `recent_frames` is the number of frames to keep from the beginning of the list,
366
+ /// the most recent stack frames, `old_frames` is the last at the end of the list of frames,
367
+ /// the oldest frames up the stack.
368
+ ///
369
+ /// It makes sense to keep some of the old frames in recursion cases to see what actually caused
370
+ /// the recursion.
371
+ fn enforce_frame_hard_limit (
372
+ frames : & mut Array < Frame > ,
373
+ meta : & mut Meta ,
374
+ recent_frames : usize ,
375
+ old_frames : usize ,
376
+ ) {
364
377
let original_length = frames. len ( ) ;
378
+ let limit = recent_frames + old_frames;
365
379
if original_length > limit {
366
380
meta. set_original_length ( Some ( original_length) ) ;
367
- let _ = frames. drain ( 0 ..original_length - limit ) ;
381
+ let _ = frames. drain ( old_frames ..original_length - recent_frames ) ;
368
382
}
369
383
}
370
384
@@ -823,7 +837,13 @@ mod tests {
823
837
] ) ;
824
838
825
839
processor:: apply ( & mut frames, |f, m| {
826
- enforce_frame_hard_limit ( f, m, 3 ) ;
840
+ enforce_frame_hard_limit ( f, m, 3 , 0 ) ;
841
+ Ok ( ( ) )
842
+ } )
843
+ . unwrap ( ) ;
844
+
845
+ processor:: apply ( & mut frames, |f, m| {
846
+ enforce_frame_hard_limit ( f, m, 1 , 2 ) ;
827
847
Ok ( ( ) )
828
848
} )
829
849
. unwrap ( ) ;
@@ -850,7 +870,7 @@ mod tests {
850
870
] ) ;
851
871
852
872
processor:: apply ( & mut frames, |f, m| {
853
- enforce_frame_hard_limit ( f, m, 3 ) ;
873
+ enforce_frame_hard_limit ( f, m, 3 , 0 ) ;
854
874
Ok ( ( ) )
855
875
} )
856
876
. unwrap ( ) ;
@@ -871,6 +891,45 @@ mod tests {
871
891
) ;
872
892
}
873
893
894
+ #[ test]
895
+ fn test_frame_hard_limit_recent_old ( ) {
896
+ fn create_frame ( filename : & str ) -> Annotated < Frame > {
897
+ Annotated :: new ( Frame {
898
+ filename : Annotated :: new ( filename. into ( ) ) ,
899
+ ..Default :: default ( )
900
+ } )
901
+ }
902
+
903
+ let mut frames = Annotated :: new ( vec ! [
904
+ create_frame( "foo1.py" ) ,
905
+ create_frame( "foo2.py" ) ,
906
+ create_frame( "foo3.py" ) ,
907
+ create_frame( "foo4.py" ) ,
908
+ create_frame( "foo5.py" ) ,
909
+ ] ) ;
910
+
911
+ processor:: apply ( & mut frames, |f, m| {
912
+ enforce_frame_hard_limit ( f, m, 2 , 1 ) ;
913
+ Ok ( ( ) )
914
+ } )
915
+ . unwrap ( ) ;
916
+
917
+ let mut expected_meta = Meta :: default ( ) ;
918
+ expected_meta. set_original_length ( Some ( 5 ) ) ;
919
+
920
+ assert_eq ! (
921
+ frames,
922
+ Annotated (
923
+ Some ( vec![
924
+ create_frame( "foo1.py" ) ,
925
+ create_frame( "foo4.py" ) ,
926
+ create_frame( "foo5.py" ) ,
927
+ ] ) ,
928
+ expected_meta
929
+ )
930
+ ) ;
931
+ }
932
+
874
933
#[ test]
875
934
fn test_slim_frame_data_under_max ( ) {
876
935
let mut frames = vec ! [ Annotated :: new( Frame {
0 commit comments