Skip to content

Commit aab4915

Browse files
Annotation processors: improve error with unnamed packages (#236)
1 parent 5a3fc24 commit aab4915

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

arrow-libs/core/arrow-meta/arrow-meta-test-models/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
}
66

77
apply from: "$DOC_CREATION"
8+
apply from: "$SUB_PROJECT"
89

910
dependencies {
1011
compileOnly "com.google.auto.service:auto-service:$GOOGLE_AUTO_SERVICE_VERSION"

arrow-libs/core/arrow-meta/src/main/java/arrow/common/utils/AbstractProcessor.kt

+9-13
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,16 @@ fun Filer.writeSafe(
128128
logger: ((message: CharSequence) -> Unit)? = null,
129129
vararg originatingElements: Element?
130130
) = catchDoubleAttempt({
131-
val filerSourceFile = createResource(
132-
StandardLocation.SOURCE_OUTPUT,
133-
pkg,
134-
"$name.kt",
135-
*originatingElements
136-
)
137-
try {
138-
filerSourceFile.openWriter().use { writer -> writer.append(fileString) }
139-
} catch (e: Exception) {
140-
try {
141-
filerSourceFile.delete()
142-
} catch (ignored: Exception) {
131+
when (pkg) {
132+
"unnamed package" -> knownError("package not found")
133+
else -> {
134+
val filerSourceFile = createResource(StandardLocation.SOURCE_OUTPUT, pkg, "$name.kt", *originatingElements)
135+
try {
136+
filerSourceFile.openWriter().use { writer -> writer.append(fileString) }
137+
} catch (exception: IOException) {
138+
knownError("Cannot create the file: ${exception.message}")
139+
}
143140
}
144-
throw e
145141
}
146142
}) {
147143
logger?.invoke("$it by $pkg.$name")

0 commit comments

Comments
 (0)