I have an Azure Function that is triggered by some blob creation, is doing some transforms (OCR mostly) and writes the result again to Blob:
[FunctionName("Ocr")]
public static async Task Run([BlobTrigger("input/{name}")]CloudBlockBlob myBlob,[Blob("output/{name}_{DateTime}.txt", FileAccess.Write)] TextWriter resultTextFile, string name,ILogger log)
{
try
{
var ocrResult = await DoOcr(name);
// This only happens if no exception was thrown
await resultTextFile.WriteAsync(ocrResult.Text);
}
catch (Exception e)
{
log.LogError(e, $"Exception during processing. Cannot process document {name}");
}
}
This works all fine and well. However, if something goes wrong inside the "DoOcr()" function, an exception is thrown - and caught it inside my catch block - the Function ends and an empty new blob was created at "output/{name}_{DateTime}.txt".
"WriteAsync()" gets never called but why is the file still created? It does not happen if I use "CloudBlockBlob" instead of "TextWriter" in the binding.