Add details when we fail to load an element of a package definition.

This commit is contained in:
Michael Buckley 2021-07-19 17:59:54 -04:00
parent 64f1643046
commit cbb9a4355a
3 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
type: change
issue: 2805
title: "When the contents of a package are corrupt, the error messages now identify the corrupt element"

View File

@ -472,6 +472,8 @@ public class JpaPackageCache extends BasePackageCacheManager implements IHapiPac
}
private IBaseResource loadPackageEntity(NpmPackageVersionResourceEntity contents) {
try {
ResourcePersistentId binaryPid = new ResourcePersistentId(contents.getResourceBinary().getId());
IBaseBinary binary = getBinaryDao().readByPid(binaryPid);
byte[] resourceContentsBytes = BinaryUtil.getOrCreateData(myCtx, binary).getValue();
@ -479,6 +481,9 @@ public class JpaPackageCache extends BasePackageCacheManager implements IHapiPac
FhirContext packageContext = getFhirContext(contents.getFhirVersion());
return EncodingEnum.detectEncoding(resourceContents).newParser(packageContext).parseResource(resourceContents);
} catch (Exception e) {
throw new RuntimeException("Failed to load package resource " + contents, e);
}
}
@Override

View File

@ -21,6 +21,8 @@ package ca.uhn.fhir.jpa.model.entity;
*/
import ca.uhn.fhir.context.FhirVersionEnum;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -157,4 +159,20 @@ public class NpmPackageVersionResourceEntity {
myCanonicalUrl = theCanonicalUrl;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("myId", myId)
.append("myCanonicalUrl", myCanonicalUrl)
.append("myCanonicalVersion", myCanonicalVersion)
.append("myResourceType", myResourceType)
.append("myDirectory", myDirectory)
.append("myFilename", myFilename)
.append("myPackageVersion", myPackageVersion)
.append("myResSizeBytes", myResSizeBytes)
.append("myVersion", myVersion)
.toString();
}
}