@@ -9,6 +9,7 @@ import { OVERRIDE_JAVA_AGENT } from './terminal/terminal-env-overrides';
9
9
import { reportError } from '../error-tracking' ;
10
10
import { delay } from '../util/promise' ;
11
11
import { commandExists , canAccess } from '../util/fs' ;
12
+ import { ErrorLike } from '../util/error' ;
12
13
13
14
type JvmTarget = { pid : string , name : string , interceptedByProxy : number | undefined } ;
14
15
@@ -38,7 +39,12 @@ const javaBinPromise: Promise<string | false> = (async () => {
38
39
const javaTestResults = await Promise . all ( javaBinPaths . map ( async ( possibleJavaBin ) => ( {
39
40
javaBin : possibleJavaBin ,
40
41
output : await testJavaBin ( possibleJavaBin )
41
- . catch ( ( e ) => ( { exitCode : - 1 , stdout : '' , stderr : e . toString ( ) } ) )
42
+ . catch ( ( e ) => ( {
43
+ exitCode : - 1 ,
44
+ spawnError : e as ErrorLike ,
45
+ stdout : '' ,
46
+ stderr : ''
47
+ } ) )
42
48
} ) ) )
43
49
44
50
// Use the first Java in the list that succeeds:
@@ -50,26 +56,35 @@ const javaBinPromise: Promise<string | false> = (async () => {
50
56
// Some Java binaries are present, but none are usable. Log the error output for debugging:
51
57
javaTestResults . forEach ( ( testResult ) => {
52
58
console . log ( `Running ${ testResult . javaBin } :` ) ;
53
- console . log ( testResult . output . stdout ) ;
54
- console . log ( testResult . output . stderr ) ;
59
+
60
+ const { stdout, stderr } = testResult . output ;
61
+ if ( stdout ) console . log ( stdout ) ;
62
+ if ( stderr ) console . log ( stderr ) ;
63
+ if ( ! stdout && ! stderr ) console . log ( '[No output]' ) ;
64
+
65
+ if ( 'spawnError' in testResult . output ) {
66
+ const { spawnError } = testResult . output ;
67
+ console . log ( spawnError . message || spawnError ) ;
68
+ }
55
69
} ) ;
56
70
57
71
// The most common reason for this is that outdated Java versions (most notably Java 8) don't include
58
72
// the necessary APIs to attach to remote JVMs. That's inconvenient, but unavoidable & not unusual.
59
73
// Fortunately, I think most active Java developers do have a recent version of Java installed.
60
- const nonOutdatedJavaErrors = javaTestResults . filter ( ( { output } ) =>
74
+ const unusualJavaErrors = javaTestResults . filter ( ( { output } ) =>
61
75
! output . stderr . includes ( OLD_JAVA_MISSING_ATTACH_CLASS ) &&
62
- ! output . stdout . includes ( OLD_JAVA_MISSING_ATTACH_CLASS )
76
+ ! output . stdout . includes ( OLD_JAVA_MISSING_ATTACH_CLASS ) &&
77
+ ! ( 'spawnError' in output && output . spawnError . code === 'ENOENT' )
63
78
) ;
64
79
65
- if ( nonOutdatedJavaErrors . length === 0 ) {
66
- console . warn ( 'Only older Java versions were detected - Java attach APIs are not available' ) ;
67
- return false ;
80
+ if ( unusualJavaErrors . length === 0 ) {
81
+ console . warn ( '=> Java attach APIs are not available' ) ;
68
82
} else {
69
83
// If we find any other unexpected Java errors, we report them, to aid with debugging and
70
84
// detecting issues with unusual JVMs.
71
- throw new Error ( `JVM attach test failed unusually - exited with ${ nonOutdatedJavaErrors [ 0 ] . output . exitCode } ` ) ;
85
+ reportError ( new Error ( `JVM attach test failed unusually - exited with ${ unusualJavaErrors [ 0 ] . output . exitCode } ` ) ) ;
72
86
}
87
+ return false ;
73
88
} else if ( bestJava ) {
74
89
return bestJava . javaBin ;
75
90
} else {
0 commit comments