fixing potential bug in error logging