File tree Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -509,3 +509,20 @@ pub fn to_quoted_string(input: &str) -> Cow<str> {
509
509
Cow :: Owned ( format ! ( "'{}'" , & input) )
510
510
}
511
511
}
512
+
513
+ // ---------------------------------------------------------------------
514
+
515
+ // We make the limit fairly generous, we hit problems on the other
516
+ // side with javascript strings > 512 Mb.
517
+ pub const MAX_LOGGED_STRING_LEN : usize = 100_000 ;
518
+ pub fn truncate_string ( s : & str , n : usize ) -> String {
519
+ let chars: Vec < char > = s. chars ( ) . collect ( ) ;
520
+ if chars. len ( ) > n {
521
+ format ! ( "{}..." , chars. iter( ) . take( n) . collect:: <String >( ) )
522
+ } else {
523
+ s. to_string ( )
524
+ }
525
+ }
526
+ pub fn limit_logged_string ( s : & str ) -> String {
527
+ truncate_string ( s, MAX_LOGGED_STRING_LEN )
528
+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ use std::time::Duration;
21
21
use anyhow:: bail;
22
22
use anyhow:: Context ;
23
23
use anyhow:: Result ;
24
+ use elp_base_db:: limit_logged_string;
24
25
use elp_types_db:: eqwalizer:: types:: Type ;
25
26
use elp_types_db:: eqwalizer:: EqwalizerDiagnostic ;
26
27
use fxhash:: FxHashMap ;
@@ -99,7 +100,7 @@ impl IpcHandle {
99
100
err, command_str, cmd, & attr
100
101
) ;
101
102
// Show up in error log
102
- log:: error!( "{error_str}" ) ;
103
+ log:: error!( "{}" , limit_logged_string ( & error_str ) ) ;
103
104
// And show up as an eqwalizer error
104
105
bail ! ( error_str) ;
105
106
}
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ use anyhow::Context;
21
21
use anyhow:: Result ;
22
22
use ast:: Error ;
23
23
use ast:: Pos ;
24
+ use elp_base_db:: limit_logged_string;
24
25
use elp_base_db:: ModuleName ;
25
26
use elp_base_db:: ProjectId ;
26
27
use elp_types_db:: eqwalizer:: types:: Type ;
@@ -327,8 +328,8 @@ fn do_typecheck(
327
328
}
328
329
msg => {
329
330
log:: warn!(
330
- "received unexpected message from eqwalizer, ignoring: {:? }" ,
331
- msg
331
+ "received unexpected message from eqwalizer, ignoring: {}" ,
332
+ limit_logged_string ( & format! ( "{:?}" , msg) )
332
333
)
333
334
}
334
335
}
@@ -464,8 +465,8 @@ fn get_module_diagnostics(
464
465
}
465
466
msg => {
466
467
log:: warn!(
467
- "received unexpected message from eqwalizer, ignoring: {:? }" ,
468
- msg
468
+ "received unexpected message from eqwalizer, ignoring: {}" ,
469
+ limit_logged_string ( & format! ( "{:?}" , msg) )
469
470
)
470
471
}
471
472
}
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ use std::panic::RefUnwindSafe;
13
13
use std:: path:: PathBuf ;
14
14
use std:: sync:: Arc ;
15
15
16
+ use elp_base_db:: limit_logged_string;
16
17
use elp_base_db:: salsa;
17
18
use elp_base_db:: AbsPathBuf ;
18
19
use elp_base_db:: FileId ;
@@ -398,7 +399,11 @@ impl TypedSemantic for RootDatabase {
398
399
) ,
399
400
EqwalizerDiagnostics :: NoAst { .. } => Some ( vec ! [ ] ) ,
400
401
EqwalizerDiagnostics :: Error ( err) => {
401
- log:: error!( "EqWAlizer failed for {}: {}" , module. as_str( ) , err) ;
402
+ log:: error!(
403
+ "EqWAlizer failed for {}: {}" ,
404
+ module. as_str( ) ,
405
+ limit_logged_string( err)
406
+ ) ;
402
407
Some ( vec ! [ ] )
403
408
}
404
409
}
You can’t perform that action at this time.
0 commit comments