Skip to content

Commit 3f3dae0

Browse files
committed
Add check for writing to an already existing file
1 parent 00dd9c4 commit 3f3dae0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Microsoft.OpenApi.Tool/OpenApiService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Linq;
44
using System.Net;
@@ -63,6 +63,11 @@ public static void ProcessOpenApiDocument(
6363
throw new ArgumentException(string.Join(Environment.NewLine, context.Errors.Select(e => e.Message).ToArray()));
6464
}
6565

66+
if (output.Exists)
67+
{
68+
throw new IOException("The file you're writing to already exists.Please input a new output path.");
69+
}
70+
6671
using var outputStream = output?.Create();
6772

6873
var textWriter = outputStream != null ? new StreamWriter(outputStream) : Console.Out;

0 commit comments

Comments
 (0)