Merge pull request #2806 from hapifhir/2805-improve-package-error-messages

Add details when we fail to load an element of a package definition.
This commit is contained in:
michaelabuckley 2021-07-20 15:41:05 -04:00 committed by GitHub
commit 0ebf274d36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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();
}
}