Skip to content

Commit

Permalink
fix: avoid failure when index restore misses layer-..json file
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Feb 18, 2023
1 parent bba2c1b commit 9e8edc8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import actions.cache.RestoreType
import actions.core.ActionFailedException
import actions.core.debug
import actions.core.info
import actions.core.warning
import actions.glob.removeFiles
import com.github.burrunan.formatBytes
import com.github.burrunan.gradle.github.stateVariable
Expand Down Expand Up @@ -60,6 +61,9 @@ class LayeredCache(
paths = listOf(layers.cachedName),
)

override fun toString(): String =
"Cache $name, primaryKey=$primaryKey, restoreKeys=$restoreKeys, "

private fun CacheLayer.toCache(stateKey: String) =
DefaultCache(
name = name,
Expand All @@ -83,7 +87,10 @@ class LayeredCache(
if (indexRestoreType == RestoreType.None) {
return RestoreType.None
}
val cacheIndex = layers.decode() ?: throw ActionFailedException("${layers.cachedName} is not found")
val cacheIndex = layers.decode() ?: run {
warning("Unable to restore cache $this")
return RestoreType.Unknown
}

var restoreType: RestoreType = when (indexRestoreType) {
is RestoreType.Exact -> RestoreType.Exact(indexRestoreType.path.removePrefix("$version-index-"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@

package actions.core

class ActionFailedException(override val message: String, cause: Throwable?): Throwable(message, cause) {
constructor(message: String): this(message, null)
}
class ActionFailedException(override val message: String, cause: Throwable? = null) :
Throwable(message, cause)

0 comments on commit 9e8edc8

Please sign in to comment.