Elffuss BraidHub

kikocis/continue public

fix: avoid NPE when failing to create missing dirs on writeFile (#7833)

Related to #7829

We have test coverage for this case (the directory is created automatically if missing), but apparently there's a scenario where it can't be created. This change makes the code handle such situations gracefully: instead of throwing an error, the file simply won't be created.

Added extra logging to help debug this issue further.
Changesetff45c71a54a7de528ebda80f3845ba1088205b66680ea7923a3abdc6978dc381
AuthorJakub Błach <jakubblach@gmail.com> · 2025-09-18 21:30 +02:00
CommitterGitHub <noreply@github.com> · 2025-09-18 12:30 -07:00
Parents8daf96c029f5

Browse the files at this changeset

1 file changed

modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/file/FileUtils.kt +8 −2
@@ -4,6 +4,7 @@
44 import com.github.continuedev.continueintellijextension.FileType
55 import com.intellij.openapi.application.runReadAction
66 import com.intellij.openapi.application.runWriteAction
7+import com.intellij.openapi.diagnostic.Logger
78 import com.intellij.openapi.fileEditor.FileDocumentManager
89 import com.intellij.openapi.fileEditor.FileEditorManager
910 import com.intellij.openapi.project.Project
@@ -24,10 +25,11 @@
2425 fun writeFile(fileUri: String, content: String) {
2526 val path = VfsUtilCore.urlToPath(fileUri)
2627 val pathDirectory = VfsUtil.getParentDir(path)
27- ?: return
28+ ?: return LOG.warn("Parent directory is null for $path")
2829 val vfsDirectory = VfsUtil.createDirectories(pathDirectory)
30+ ?: return LOG.warn("Could not create directories for $path")
2931 val pathFilename = VfsUtil.extractFileName(path)
30- ?: return
32+ ?: return LOG.warn("Could not get filename for $path")
3133 runWriteAction {
3234 val newFile = vfsDirectory.createChildData(this, pathFilename)
3335 VfsUtil.saveText(newFile, content)
@@ -107,4 +109,8 @@
107109 }
108110 return fileUri
109111 }
112+
113+ private companion object {
114+ private val LOG = Logger.getInstance(FileUtils::class.java)
115+ }
110116 }
No newline at the end of the file