Guard against possible errors in ScopeManager.

These errors don't seem likely in normal use, but we're seeing intermittent failure
on the test machine which could be related.

This is a possible fix for #5968. The stack trace in that issue points to the `beforeFirst` code, so it's possible that the environment is just not fully set up at the time that the initial `setConfig` is called.