Skip to content

Commit

Permalink
Fix/expand pre execution error (#63)
Browse files Browse the repository at this point in the history
* Add extra fields to pre execution error to help with debugging.
  • Loading branch information
Stephen Cirner authored Jun 29, 2021
1 parent 322e903 commit 8ac68c7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
12 changes: 0 additions & 12 deletions os-client/src/main/kotlin/io/provenance/os/client/OsClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ open class OsClient(
}
}

fun get(uri: String, publicKey: PublicKey): DIMEInputStream {
if (uri.isEmpty()) {
throw IllegalArgumentException("Empty uri passed.")
}
val u = URI(uri)
if (u.scheme != "object") {
throw IllegalArgumentException("Unable to retrieve object for URI with scheme ${u.scheme}")
}

return get(u.path.substring(1).base64Decode(), publicKey)
}

fun get(sha512: ByteArray, publicKey: PublicKey, deadlineSeconds: Long = 60L): DIMEInputStream {
if (sha512.size != 64) {
throw IllegalArgumentException("Provided SHA-512 must be byte array of size 64, found size: ${sha512.size}")
Expand Down
3 changes: 2 additions & 1 deletion p8e-common/src/main/kotlin/io/p8e/exception/Exception.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.grpc.StatusException
import io.grpc.Metadata
import io.grpc.StatusRuntimeException
import io.p8e.proto.ContractScope
import io.p8e.proto.Contracts.Contract
import io.p8e.util.*

sealed class P8eError {
Expand All @@ -15,7 +16,7 @@ sealed class P8eError {
data class ProtoParse(val message: String) : P8eError()
data class NotFound(val message: String) : P8eError()
data class ExecutionError(val envelopeError: ContractScope.EnvelopeError) : P8eError()
data class PreExecutionError(val t: Throwable) : P8eError()
data class PreExecutionError(val t: Throwable, val isFragment: Boolean, val contract: Contract, val envelope: ContractScope.Envelope) : P8eError()
data class Unknown(val t: Throwable) : P8eError()

companion object {
Expand Down
17 changes: 12 additions & 5 deletions p8e-sdk/src/main/kotlin/io/p8e/proxy/Contract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,6 @@ class Contract<T: P8eContract>(
this.stagedContract.toAudience(envelope.scope)
)

permissionUpdater.saveConstructorArguments()

// Build the envelope for this execution
this.executionEnvelope = envelope.toBuilder()
.setExecutionUuid(this.stagedExecutionUuid)
Expand All @@ -459,14 +457,16 @@ class Contract<T: P8eContract>(
.clearSignatures()
.build()

permissionUpdater.saveConstructorArguments()

// TODO This probably should be removed since we can't on the fly install specs. It would have
// to get saved during bootstrap addSpec
saveSpec(contractManager)

executed.set(true)

permissionUpdater.saveProposedFacts(this.stagedExecutionUuid.toUuidProv(), this.stagedProposedProtos)

executed.set(true)

return this.executionEnvelope
}

Expand Down Expand Up @@ -719,7 +719,14 @@ class Contract<T: P8eContract>(
execute(this.packageContract())
}
} catch (t: Throwable) {
Either.Left(P8eError.PreExecutionError(t))
Either.Left(
P8eError.PreExecutionError(
t,
isFragment = isFragment,
contract = this.stagedContract,
envelope = if (this.executionEnvelope != Envelope.getDefaultInstance()) this.executionEnvelope else this.envelope,
)
)
}

private fun execute(
Expand Down

0 comments on commit 8ac68c7

Please sign in to comment.