@@ -63,23 +63,25 @@ struct ProcessInvocationBridge : ParsableCommand {
6363 defer { buffer. deallocate ( ) }
6464
6565 let rawBuffer = UnsafeMutableRawBufferPointer ( buffer)
66- guard try FileDescriptor . standardInput. read ( into: rawBuffer) == rawBuffer. count else {
66+ let readCount = try FileDescriptor . standardInput. read ( into: rawBuffer)
67+ guard readCount == rawBuffer. count else {
6768 /* TODO: Use an actual error */
68- Self . logger. error ( " unexpected number of bytes read from stdin" )
69+ Self . logger. error ( " Unexpected number of bytes read from stdin. " , metadata : [ " expected_count " : " \( rawBuffer . count ) " , " actual_count " : " \( readCount ) " ] )
6970 throw ExitCode ( rawValue: 1 )
7071 }
7172 let nFds = buffer. baseAddress!. pointee
72- Self . logger. trace ( " Will receive \( nFds) fds " )
73+ Self . logger. trace ( " Will receive fds. " , metadata : [ " fd_count " : " \( nFds) " ] )
7374
7475 /* Then we read the fds */
7576 for _ in 0 ..< nFds {
7677 let ( receivedFd, destinationFd) = try receiveFd ( from: FileDescriptor . standardInput. rawValue)
77- Self . logger. trace ( " Received fd \( receivedFd) , with expected destination fd \( destinationFd) ) " )
78+ Self . logger. trace ( " Received fd. " , metadata : [ " received_fd " : " \( receivedFd) " , " expected_destination_fd " : " \( destinationFd) " ] )
7879 /* As we have not closed any received fd yet, it should not be possible to received the same fd twice. */
7980 assert ( receivedFdToDestinationFd [ receivedFd] == nil )
8081
8182 if let oldReceivedFd = destinationFdToReceivedFd [ destinationFd] {
82- Self . logger. warning ( " Internal Launcher: Received expected destination fd \( destinationFd) more than once! Caller did a mistake. Latest received fd ( \( receivedFd) for now) wins. " )
83+ Self . logger. warning ( " Internal Launcher: Received an expected destination fd more than once! Caller did a mistake. Latest received fd wins. " ,
84+ metadata: [ " expected_destination_fd " : " \( destinationFd) " , " latest_received_fd_to_date " : " \( receivedFd) " ] )
8385
8486 /* We should close the old fd as we won’t be using it at all. */
8587 try FileDescriptor ( rawValue: oldReceivedFd) . close ( )
@@ -93,7 +95,7 @@ struct ProcessInvocationBridge : ParsableCommand {
9395 receivedFdToDestinationFd [ receivedFd] = destinationFd
9496 destinationFdToReceivedFd [ destinationFd] = receivedFd
9597 }
96- Self . logger. trace ( " Received all fds " )
98+ Self . logger. trace ( " Received all fds. " )
9799 }
98100
99101 /* We may modify destinationFdToReceivedFd values, so no (key, value) iteration type. */
@@ -131,7 +133,7 @@ struct ProcessInvocationBridge : ParsableCommand {
131133 }
132134
133135 try withCStrings ( [ toolName] + toolArguments, scoped: { cargs in
134- Self . logger. trace ( " exec’ing \( toolName) " )
136+ Self . logger. trace ( " exec’ing. " , metadata : [ " executable " : " \( toolName) " ] )
135137 let ret : Int32
136138 if usePath {
137139#if !os(Linux)
@@ -183,7 +185,7 @@ struct ProcessInvocationBridge : ParsableCommand {
183185 ret = execv ( toolName, cargs)
184186 }
185187 assert ( ret != 0 , " exec should not return if it was successful. " )
186- Self . logger. error ( " Error running executable \( toolName) : \( Errno ( rawValue: errno) . description ) " )
188+ Self . logger. error ( " Error running executable. " , metadata : [ " executabl " : " \( toolName) " , " error " : " \( Errno ( rawValue: errno) ) " ] )
187189 /* TODO: Is this the exit code we really want? */throw ExitCode( errno)
188190 } )
189191
@@ -228,7 +230,7 @@ struct ProcessInvocationBridge : ParsableCommand {
228230 * let ok = (receivedBytes == 0 || errno == ECONNRESET)
229231 * And we returned nil if ok was true. */
230232 /* TODO: Is it ok to log in this context? I’d say probably yeah, but too tired to validate now. */
231- Self . logger. error ( " cannot read from socket: \( Errno ( rawValue: errno) ) " )
233+ Self . logger. error ( " Cannot read from socket. " , metadata : [ " error " : " \( Errno ( rawValue: errno) ) " ] )
232234 /* TODO: Use an actual error */throw ExitCode ( rawValue: 1 )
233235 }
234236
0 commit comments