<commit_before>package com.evolveum.midpoint.provisioning.consistency.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.provisioning.api.GenericConnectorException;
import com.evolveum.midpoint.provisioning.consistency.api.ErrorHandler;
import com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.SystemException;

@Component
public class ErrorHandlerFactory {
	
	@Autowired(required=true)
	CommunicationExceptionHandler communicationExceptionHandler;
	
	@Autowired(required=true)
	SchemaExceptionHandler schemaExceptionHandler;
	
	@Autowired(required=true)
	ObjectNotFoundHandler objectNotFoundHandler;
	
	@Autowired(required=true)
	ObjectAlreadyExistHandler objectAlreadyExistsHandler;
	
	@Autowired(required=true)
	GenericErrorHandler genericErrorHandler;
	
	@Autowired(required=true)
	ConfigurationExceptionHandler configurationExceptionHandler;
	
	@Autowired(required=true)
	SecurityViolationHandler securityViolationHandler;
	
	
//	public CommunicationExceptionHandler getCommunicationExceptionHandler() {
//		return communicationExceptionHandler;
//	}
//	public void setCommunicationExceptionHandler(CommunicationExceptionHandler communicationExceptionHandler) {
//		this.communicationExceptionHandler = communicationExceptionHandler;
//	}
	
	
	
	public ErrorHandler createErrorHandler(Exception ex){
		if (ex instanceof CommunicationException){
			return communicationExceptionHandler;
		}
		if (ex instanceof GenericConnectorException){
			return genericErrorHandler;
		}
		if (ex instanceof ObjectAlreadyExistsException){
			return objectAlreadyExistsHandler;
		}
		if (ex instanceof ObjectNotFoundException){
			return objectNotFoundHandler;
		}
		if (ex instanceof SchemaException){
			return schemaExceptionHandler;
		}
		if (ex instanceof ConfigurationException){
			return configurationExceptionHandler;
		}
		if (ex instanceof SecurityViolationException){
			return securityViolationHandler;
		}
		
		throw new SystemException("Unknown error occurred: "+ex.getMessage(), ex);
	}
	
	

}
<commit_msg>Better error message.<commit_after>package com.evolveum.midpoint.provisioning.consistency.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.provisioning.api.GenericConnectorException;
import com.evolveum.midpoint.provisioning.consistency.api.ErrorHandler;
import com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.SystemException;

@Component
public class ErrorHandlerFactory {
	
	@Autowired(required=true)
	CommunicationExceptionHandler communicationExceptionHandler;
	
	@Autowired(required=true)
	SchemaExceptionHandler schemaExceptionHandler;
	
	@Autowired(required=true)
	ObjectNotFoundHandler objectNotFoundHandler;
	
	@Autowired(required=true)
	ObjectAlreadyExistHandler objectAlreadyExistsHandler;
	
	@Autowired(required=true)
	GenericErrorHandler genericErrorHandler;
	
	@Autowired(required=true)
	ConfigurationExceptionHandler configurationExceptionHandler;
	
	@Autowired(required=true)
	SecurityViolationHandler securityViolationHandler;
	
	
//	public CommunicationExceptionHandler getCommunicationExceptionHandler() {
//		return communicationExceptionHandler;
//	}
//	public void setCommunicationExceptionHandler(CommunicationExceptionHandler communicationExceptionHandler) {
//		this.communicationExceptionHandler = communicationExceptionHandler;
//	}
	
	
	
	public ErrorHandler createErrorHandler(Exception ex){
		if (ex instanceof CommunicationException){
			return communicationExceptionHandler;
		}
		if (ex instanceof GenericConnectorException){
			return genericErrorHandler;
		}
		if (ex instanceof ObjectAlreadyExistsException){
			return objectAlreadyExistsHandler;
		}
		if (ex instanceof ObjectNotFoundException){
			return objectNotFoundHandler;
		}
		if (ex instanceof SchemaException){
			return schemaExceptionHandler;
		}
		if (ex instanceof ConfigurationException){
			return configurationExceptionHandler;
		}
		if (ex instanceof SecurityViolationException){
			return securityViolationHandler;
		}
		
		throw new SystemException("Unknown error occurred: "+ex.getClass().getName()+": "+ex.getMessage(), ex);
	}
	
	

}

{'fraction_non_alphanumeric': 0.07418452935694315, 'fraction_numerical': 0.0, 'mean_word_length': 5.6824408468244085, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7397859', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1407, 'n_words': 233}