From e8c50a4bc59930404e12fe759e7347ab73e665e7 Mon Sep 17 00:00:00 2001 From: yma Date: Tue, 26 Mar 2024 10:52:14 +0800 Subject: [PATCH] Add StreamConstraintsException catch and response for npm contents generating --- .../npm/jaxrs/NPMContentAccessHandler.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/addons/pkg-npm/jaxrs/src/main/java/org/commonjava/indy/pkg/npm/jaxrs/NPMContentAccessHandler.java b/addons/pkg-npm/jaxrs/src/main/java/org/commonjava/indy/pkg/npm/jaxrs/NPMContentAccessHandler.java index df470fc1ab..216edb3767 100644 --- a/addons/pkg-npm/jaxrs/src/main/java/org/commonjava/indy/pkg/npm/jaxrs/NPMContentAccessHandler.java +++ b/addons/pkg-npm/jaxrs/src/main/java/org/commonjava/indy/pkg/npm/jaxrs/NPMContentAccessHandler.java @@ -16,6 +16,7 @@ package org.commonjava.indy.pkg.npm.jaxrs; import com.fasterxml.jackson.core.StreamReadConstraints; +import com.fasterxml.jackson.core.exc.StreamConstraintsException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.codec.binary.Base64; @@ -121,6 +122,13 @@ public Response doCreate( String packageType, String type, String name, String p // generate .http-metadata.json for hosted repo to resolve npm header requirements generateHttpMetadataHeaders( metadataFile, generated, request, response ); } + catch ( final StreamConstraintsException e ) + { + logger.error( String.format( + "Failed to upload due to violation of Jackson stream constraint: %s to: %s. Reason: %s", path, name, + e.getMessage() ), e ); + response = responseHelper.formatResponse( e, builderModifier ); + } catch ( final IndyWorkflowException | IOException e ) { logger.error( String.format( "Failed to upload: %s to: %s. Reason: %s", path, name, e.getMessage() ), e ); @@ -461,6 +469,7 @@ private Object replaceOrigin( String baseUri, String proxyOrigin ) } private List generateNPMContentsFromTransfer( final Transfer transfer, final EventMetadata eventMetadata ) + throws StreamConstraintsException { if ( transfer == null || !transfer.exists() ) { @@ -526,9 +535,18 @@ private List generateNPMContentsFromTransfer( final Transfer transfer, tarballTarget = transfers.getCacheReference( new ConcreteResource( resource.getLocation(), tarballPath ) ); } + catch ( final StreamConstraintsException e ) + { + // Refer to https://www.javadoc.io/static/com.fasterxml.jackson.core/jackson-core/2.15.2/com/fasterxml/jackson/core/exc/StreamConstraintsException.html + logger.error( String.format( + "[NPM] Json node parse failed due to violation of Jackson stream constraint: %s. Reason: %s", + resource, e.getMessage() ), e ); + throw e; + } catch ( final IOException e ) { - logger.error( String.format( "[NPM] Json node parse failed for resource: %s. Reason: %s", resource, e.getMessage() ), e ); + logger.error( String.format( "[NPM] Json node parse failed for resource: %s. Reason: %s", resource, + e.getMessage() ), e ); } if ( versionTarget == null || tarballTarget == null )