Any reason not to use this form?
```
var currentDoc = DocumentManager.getCurrentDocument(),
    provider = currentDoc && getProvider(currentDoc.file);
```