Throw proper exception when writing an asset with no targetPath: refactoring