Skip to content

Commit

Permalink
Include the exception message in error response (apache#14395)
Browse files Browse the repository at this point in the history
  • Loading branch information
shounakmk219 authored Nov 7, 2024
1 parent 4cffd91 commit e35f43c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ private SuccessResponse addSchema(Schema schema, boolean override, boolean force
throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.BAD_REQUEST, e);
} catch (Exception e) {
_controllerMetrics.addMeteredGlobalValue(ControllerMeter.CONTROLLER_SCHEMA_UPLOAD_ERROR, 1L);
throw new ControllerApplicationException(LOGGER, String.format("Failed to add new schema %s.", schemaName),
Response.Status.INTERNAL_SERVER_ERROR, e);
throw new ControllerApplicationException(LOGGER, String.format("Failed to add new schema %s. Reason: %s",
schemaName, e.getMessage()), Response.Status.INTERNAL_SERVER_ERROR, e);
}
}

Expand Down Expand Up @@ -474,8 +474,8 @@ private SuccessResponse updateSchema(String schemaName, Schema schema, boolean r
Response.Status.NOT_FOUND, e);
} catch (Exception e) {
_controllerMetrics.addMeteredGlobalValue(ControllerMeter.CONTROLLER_SCHEMA_UPLOAD_ERROR, 1L);
throw new ControllerApplicationException(LOGGER, String.format("Failed to update schema %s", schemaName),
Response.Status.INTERNAL_SERVER_ERROR, e);
throw new ControllerApplicationException(LOGGER, String.format("Failed to update schema %s. Reason: %s",
schemaName, e.getMessage()), Response.Status.INTERNAL_SERVER_ERROR, e);
}
}

Expand Down Expand Up @@ -520,7 +520,7 @@ private Pair<Schema, Map<String, Object>> getSchemaAndUnrecognizedPropertiesFrom
try {
return JsonUtils.stringToObjectAndUnrecognizedProperties(schemaJsonString, Schema.class);
} catch (Exception e) {
String msg = String.format("Invalid schema config json string: %s", schemaJsonString);
String msg = String.format("Invalid schema config json string: %s. Reason: %s", schemaJsonString, e.getMessage());
throw new ControllerApplicationException(LOGGER, msg, Response.Status.BAD_REQUEST, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public ObjectNode checkTableConfig(String tableConfigStr,
tableConfigAndUnrecognizedProperties =
JsonUtils.stringToObjectAndUnrecognizedProperties(tableConfigStr, TableConfig.class);
} catch (IOException e) {
String msg = String.format("Invalid table config json string: %s", tableConfigStr);
String msg = String.format("Invalid table config json string: %s. Reason: %s", tableConfigStr, e.getMessage());
throw new ControllerApplicationException(LOGGER, msg, Response.Status.BAD_REQUEST, e);
}
TableConfig tableConfig = tableConfigAndUnrecognizedProperties.getLeft();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ public String getTaskMetadataByTable(
return _pinotHelixTaskResourceManager.getTaskMetadataByTable(taskType, tableNameWithType);
} catch (JsonProcessingException e) {
throw new ControllerApplicationException(LOGGER, String
.format("Failed to format task metadata into Json for task type: %s from table: %s", taskType,
tableNameWithType), Response.Status.INTERNAL_SERVER_ERROR, e);
.format("Failed to format task metadata into Json for task type: %s from table: %s. Reason: %s", taskType,
tableNameWithType, e.getMessage()), Response.Status.INTERNAL_SERVER_ERROR, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ private void persistInstancePartitionsHelper(InstancePartitions instancePartitio
InstancePartitionsUtils.persistInstancePartitions(_pinotHelixResourceManager.getPropertyStore(),
instancePartitions);
} catch (Exception e) {
throw new ControllerApplicationException(LOGGER, "Caught Exception while persisting the instance partitions",
Response.Status.INTERNAL_SERVER_ERROR, e);
throw new ControllerApplicationException(LOGGER, "Caught Exception while persisting the instance partitions. "
+ "Reason: " + e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR, e);
}
}

Expand Down Expand Up @@ -605,7 +605,7 @@ public String changeTenantState(
} catch (Exception e) {
_controllerMetrics.addMeteredGlobalValue(ControllerMeter.CONTROLLER_INSTANCE_POST_ERROR, 1L);
throw new ControllerApplicationException(LOGGER,
String.format("Error during %s operation for instance: %s", type, instance),
String.format("Error during %s operation for instance: %s. Reason: %s", type, instance, e.getMessage()),
Response.Status.INTERNAL_SERVER_ERROR, e);
}
return instanceResult.toString();
Expand Down Expand Up @@ -661,7 +661,8 @@ public SuccessResponse deleteTenant(
return new SuccessResponse("Successfully deleted tenant " + tenantName);
}
_controllerMetrics.addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_TENANT_DELETE_ERROR, 1L);
throw new ControllerApplicationException(LOGGER, "Error deleting tenant", Response.Status.INTERNAL_SERVER_ERROR);
throw new ControllerApplicationException(LOGGER, "Error deleting tenant. Reason: " + res.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR);
}

@POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public String estimateHeapUsage(String tableSchemaConfigStr,
tableSchemaConfig = JsonUtils.stringToObject(tableSchemaConfigStr, TableAndSchemaConfig.class);
} catch (IOException e) {
throw new ControllerApplicationException(LOGGER,
String.format("Invalid TableSchemaConfigs json string: %s", tableSchemaConfigStr),
String.format("Invalid TableSchemaConfigs json string: %s. Reason: %s", tableSchemaConfigStr, e.getMessage()),
Response.Status.BAD_REQUEST, e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ public ConfigSuccessResponse addConfig(
} catch (Exception e) {
_controllerMetrics.addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_ADD_ERROR, 1L);
if (e instanceof InvalidTableConfigException) {
throw new ControllerApplicationException(LOGGER, String.format("Invalid TableConfigs: %s", rawTableName),
Response.Status.BAD_REQUEST, e);
throw new ControllerApplicationException(LOGGER, String.format("Invalid TableConfigs: %s. Reason: %s",
rawTableName, e.getMessage()), Response.Status.BAD_REQUEST, e);
} else if (e instanceof TableAlreadyExistsException) {
throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.CONFLICT, e);
} else {
Expand Down Expand Up @@ -333,8 +333,8 @@ public ConfigSuccessResponse updateConfig(
"'tableName' in TableConfigs: %s must match provided tableName: %s", tableConfigs.getTableName(), tableName);
tableConfigs.setTableName(tableName);
} catch (Exception e) {
throw new ControllerApplicationException(LOGGER, String.format("Invalid TableConfigs: %s", tableName),
Response.Status.BAD_REQUEST, e);
throw new ControllerApplicationException(LOGGER, String.format("Invalid TableConfigs: %s. Reason: %s", tableName,
e.getMessage()), Response.Status.BAD_REQUEST, e);
}

if (!_pinotHelixResourceManager.hasOfflineTable(tableName) && !_pinotHelixResourceManager.hasRealtimeTable(
Expand Down Expand Up @@ -406,7 +406,8 @@ public String validateConfig(String tableConfigsStr,
JsonUtils.stringToObjectAndUnrecognizedProperties(tableConfigsStr, TableConfigs.class);
} catch (IOException e) {
throw new ControllerApplicationException(LOGGER,
String.format("Invalid TableConfigs json string: %s", tableConfigsStr), Response.Status.BAD_REQUEST, e);
String.format("Invalid TableConfigs json string: %s. Reason: %s", tableConfigsStr, e.getMessage()),
Response.Status.BAD_REQUEST, e);
}
String databaseName = DatabaseUtils.extractDatabaseFromHttpHeaders(httpHeaders);
TableConfigs tableConfigs = tableConfigsAndUnrecognizedProps.getLeft();
Expand Down

0 comments on commit e35f43c

Please sign in to comment.