Skip to content

Commit

Permalink
pretty print contract IDs properly (digital-asset#11359)
Browse files Browse the repository at this point in the history
CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da authored Oct 29, 2021
1 parent bb4f4c5 commit 3098b70
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ object Error {
final case class DamlException(error: interpretation.Error) extends Error {
override def message: String = error match {
case interpretation.Error.ContractNotFound(cid) =>
s"Contract could not be found with id $cid"
s"Contract could not be found with id ${cid.coid}"
case interpretation.Error.ContractKeyNotFound(key) =>
s"dependency error: couldn't find key: $key"
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ private[lf] object Pretty {
case NonComparableValues =>
text("functions are not comparable")
case ContractIdComparability(globalCid) =>
text(s"The global contract ID $globalCid conflicts with a local contract ID")
text(s"The global contract ID") & prettyContractId(globalCid) &
text("conflicts with a local contract ID")
case ContractIdInContractKey(key) =>
text(
s"Contract IDs are not supported in contract keys: ${key.ensureNoCid.left.toOption.get}"
)
text("Contract IDs are not supported in contract keys:") &
prettyContractId(key.ensureNoCid.left.toOption.get)
case ValueExceedsMaxNesting =>
text(s"Value exceeds maximum nesting value of 100")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,10 @@ private[lf] object SBuiltin {
val chosenValue = onLedger.ptx.normValue(templateId, args.get(0))
val coid = getSContractId(args, 1)
val cached =
onLedger.cachedContracts.getOrElse(coid, crash(s"Contract $coid is missing from cache"))
onLedger.cachedContracts.getOrElse(
coid,
crash(s"Contract ${coid.coid} is missing from cache"),
)
val sigs = cached.signatories
val templateObservers = cached.observers
val ctrls = extractParties(NameOf.qualifiedNameOfCurrentFunc, args.get(2))
Expand Down Expand Up @@ -1024,7 +1027,7 @@ private[lf] object SBuiltin {
if (cached.templateId != templateId) {
if (onLedger.ptx.localContracts.contains(coid)) {
// This should be prevented by the type checker so it’s an internal error.
crash(s"contract $coid ($templateId) not found from partial transaction")
crash(s"contract ${coid.coid} ($templateId) not found from partial transaction")
} else {
// This is a user-error.
machine.ctrl = SEDamlException(
Expand Down Expand Up @@ -1192,7 +1195,10 @@ private[lf] object SBuiltin {
): Unit = {
val coid = getSContractId(args, 0)
val cached =
onLedger.cachedContracts.getOrElse(coid, crash(s"Contract $coid is missing from cache"))
onLedger.cachedContracts.getOrElse(
coid,
crash(s"Contract ${coid.coid} is missing from cache"),
)
val signatories = cached.signatories
val observers = cached.observers
val key = cached.key
Expand Down Expand Up @@ -1335,7 +1341,7 @@ private[lf] object SBuiltin {
case Some(PartialTransaction.KeyActive(coid))
if onLedger.ptx.localContracts.contains(coid) =>
val cachedContract = onLedger.cachedContracts
.getOrElse(coid, crash(s"Local contract $coid not in cachedContracts"))
.getOrElse(coid, crash(s"Local contract ${coid.coid} not in cachedContracts"))
val stakeholders = cachedContract.signatories union cachedContract.observers
onLedger.visibleToStakeholders(stakeholders) match {
case SVisibleToStakeholders.Visible =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ object ScenarioRunner {
case ScenarioLedger.LookupContractNotFound(coid) =>
// This should never happen, hence we don't have a specific
// error for this.
throw Error.Internal(s"contract $coid not found")
throw Error.Internal(s"contract ${coid.coid} not found")

case ScenarioLedger.LookupContractNotEffective(coid, tid, effectiveAt) =>
throw Error.ContractNotEffective(coid, tid, effectiveAt)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Error: Contract IDs are not supported in contract keys: ContractId(00fa6dbc32b678ec8a97ed0de226e397a4e2d521097b879d0146979556e7cd3e58)
Error: Contract IDs are not supported in contract keys: 00fa6dbc32b678ec8a97ed0de226e397a4e2d521097b879d0146979556e7cd3e58
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ abstract class AbstractHttpServiceIntegrationTest
status shouldBe StatusCodes.Conflict
assertStatus(output, StatusCodes.Conflict)
expectedOneErrorMessage(output) should include(
s"Contract could not be found with id ContractId($contractIdString)"
s"Contract could not be found with id $contractIdString"
)
}: Future[Assertion]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ final class ContractIdIT extends LedgerTestSuite {
// Assert V1 error code
case Failure(GrpcException(GrpcStatus(Status.Code.ABORTED, Some(msg)), _))
if !alpha.features.selfServiceErrorCodes && msg.contains(
s"Contract could not be found with id ContractId($testedCid)"
s"Contract could not be found with id $testedCid"
) =>
Success(())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private[platform] class ActiveLedgerStateManager[ALS <: ActiveLedgerState[ALS]](
if (otherContractLet.isAfter(let)) {
Some(
InvalidLedgerTime(
s"Encountered contract [$cid] with LET [$otherContractLet] greater than the LET of the transaction [$let]"
s"Encountered contract [${cid.coid}] with LET [$otherContractLet] greater than the LET of the transaction [$let]"
)
)
} else {
Expand All @@ -125,7 +125,7 @@ private[platform] class ActiveLedgerStateManager[ALS <: ActiveLedgerState[ALS]](
None
case None =>
// Contract not known
Some(Inconsistent(s"Could not lookup contract $cid"))
Some(Inconsistent(s"Could not lookup contract ${cid.coid}"))
}

def handleLeaf(
Expand Down Expand Up @@ -160,7 +160,7 @@ private[platform] class ActiveLedgerStateManager[ALS <: ActiveLedgerState[ALS]](
// A contract starts its life without being divulged at all.
divulgences = Map.empty,
key = nc.versionedKey.map(
_.assertNoCid(coid => s"Contract ID $coid found in contract key")
_.assertNoCid(coid => s"Contract ID ${coid.coid} found in contract key")
),
signatories = nc.signatories,
observers = nc.stakeholders.diff(nc.signatories),
Expand Down Expand Up @@ -196,7 +196,10 @@ private[platform] class ActiveLedgerStateManager[ALS <: ActiveLedgerState[ALS]](
case nlkup: N.NodeLookupByKey =>
// Check that the stored lookup result matches the current result
val key = nlkup.key.key.ensureNoCid.fold(
coid => throw new IllegalStateException(s"Contract ID $coid found in contract key"),
coid =>
throw new IllegalStateException(
s"Contract ID ${coid.coid} found in contract key"
),
identity,
)
val gk = GlobalKey(nlkup.templateId, key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ private[events] object TransactionLogUpdatesConversions {
contractIds + event.contractId
case (contractIds, event: ExercisedEvent) if event.consuming =>
contractIds - event.contractId
case (contractId, _) =>
throw new RuntimeException(s"Unexpected non-consuming event for contractId $contractId")
case (contractIds, _) =>
val prettyCids = contractIds.iterator.map(_.coid).mkString(", ")
throw new RuntimeException(s"Unexpected non-consuming event for contractIds $prettyCids")
}
aux.filter(ev => permanent(ev.contractId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private[platform] class MutableCacheBackedContractStore(
// (the contract might have been divulged to the readers)
// OR the contract was not found in the index
//
logger.debug(s"Checking divulgence for contractId=$contractId and readers=$readers")
logger.debug(s"Checking divulgence for contractId=${contractId.coid} and readers=$readers")
resolveDivulgenceLookup(contractStateValue, contractId, readers)
}

Expand Down Expand Up @@ -281,7 +281,7 @@ private[platform] class MutableCacheBackedContractStore(
eventSequentialId,
) =>
logger.debug(
s"State events update: Created(contractId=$contractId, globalKey=$globalKey, offset=$eventOffset, eventSequentialId=$eventSequentialId)"
s"State events update: Created(contractId=${contractId.coid}, globalKey=$globalKey, offset=$eventOffset, eventSequentialId=$eventSequentialId)"
)
case ContractStateEvent.Archived(
contractId,
Expand All @@ -291,7 +291,7 @@ private[platform] class MutableCacheBackedContractStore(
eventSequentialId,
) =>
logger.debug(
s"State events update: Archived(contractId=$contractId, globalKey=$globalKey, offset=$eventOffset, eventSequentialId=$eventSequentialId)"
s"State events update: Archived(contractId=${contractId.coid}, globalKey=$globalKey, offset=$eventOffset, eventSequentialId=$eventSequentialId)"
)
case LedgerEndMarker(eventOffset, eventSequentialId) =>
logger.debug(
Expand Down Expand Up @@ -390,7 +390,7 @@ private[platform] object MutableCacheBackedContractStore {

final case class ContractReadThroughNotFound(contractId: ContractId) extends NoStackTrace {
override def getMessage: String =
s"Contract not found for contract id $contractId. Hint: this could be due racing with a concurrent archival."
s"Contract not found for contract id ${contractId.coid}. Hint: this could be due racing with a concurrent archival."
}

private[cache] class CacheIndex(initValue: (Offset, Long)) {
Expand Down

0 comments on commit 3098b70

Please sign in to comment.