SOLR-249 -- depreating new SolrException( int ... ) in favor of new SolrException( enum ...

This also refactors all calls to new SolrException()

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@542679 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2007-05-29 22:28:21 +00:00
parent d45042208b
commit e3dd7faecf
31 changed files with 177 additions and 116 deletions

View File

@ -75,7 +75,7 @@ public class PatternTokenizerFactory implements TokenizerFactory
this.args = args;
String regex = args.get( PATTERN );
if( regex == null ) {
throw new SolrException( 500, "missing required argument: "+PATTERN );
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "missing required argument: "+PATTERN );
}
int flags = 0; // TODO? -- read flags from config CASE_INSENSITIVE, etc
pattern = Pattern.compile( regex, flags );
@ -87,7 +87,7 @@ public class PatternTokenizerFactory implements TokenizerFactory
group = Integer.parseInt( g );
}
catch( Exception ex ) {
throw new SolrException( 500, "invalid group argument: "+g );
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "invalid group argument: "+g );
}
}
}
@ -124,7 +124,7 @@ public class PatternTokenizerFactory implements TokenizerFactory
};
}
catch( IOException ex ) {
throw new SolrException( 500, ex );
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, ex );
}
}

View File

@ -38,7 +38,7 @@ import org.apache.solr.core.SolrException;
*
* "inject" (default=true) add tokens to the stream with the offset=0
*
* @version $Id:$
* @version $Id$
* @see PhoneticFilter
*/
public class PhoneticFilterFactory extends BaseTokenFilterFactory
@ -69,19 +69,19 @@ public class PhoneticFilterFactory extends BaseTokenFilterFactory
String name = args.get( ENCODER );
if( name == null ) {
throw new SolrException( 500, "Missing required parameter: "+ENCODER
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Missing required parameter: "+ENCODER
+" ["+registry.keySet()+"]" );
}
Class<? extends Encoder> clazz = registry.get(name.toUpperCase());
if( clazz == null ) {
throw new SolrException( 500, "Unknown encoder: "+name +" ["+registry.keySet()+"]" );
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Unknown encoder: "+name +" ["+registry.keySet()+"]" );
}
try {
encoder = clazz.newInstance();
}
catch (Exception e) {
throw new SolrException( 500, "Error initializing: "+name + "/"+clazz, e );
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Error initializing: "+name + "/"+clazz, e );
}
}

View File

@ -40,7 +40,7 @@ public class TrimFilterFactory extends BaseTokenFilterFactory {
updateOffsets = Boolean.valueOf( v );
}
catch( Exception ex ) {
throw new SolrException( 400, "Error reading updateOffsets value. Must be true or false.", ex );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Error reading updateOffsets value. Must be true or false.", ex );
}
}
}

View File

@ -96,7 +96,7 @@ public class Config {
return o;
} catch (XPathExpressionException e) {
throw new SolrException(500,"Error in xpath:" + path +" for " + name,e,false);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + path +" for " + name,e,false);
}
}
@ -122,12 +122,12 @@ public class Config {
} catch (XPathExpressionException e) {
SolrException.log(log,"Error in xpath",e);
throw new SolrException(500,"Error in xpath:" + xstr + " for " + name,e,false);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr + " for " + name,e,false);
} catch (SolrException e) {
throw(e);
} catch (Throwable e) {
SolrException.log(log,"Error in xpath",e);
throw new SolrException(500,"Error in xpath:" + xstr+ " for " + name,e,false);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr+ " for " + name,e,false);
}
}
@ -217,7 +217,7 @@ public class Config {
}
}
throw new SolrException(500, "Error loading class '" + cname + "'", e, false);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Error loading class '" + cname + "'", e, false);
}
}
@ -226,7 +226,7 @@ public class Config {
try {
return clazz.newInstance();
} catch (Exception e) {
throw new SolrException(500,"Error instantiating class " + clazz, e, false);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error instantiating class " + clazz, e, false);
}
}

View File

@ -157,7 +157,7 @@ final class RequestHandlers {
SolrRequestHandler old = register( name, handler );
if( old != null ) {
String msg = "multiple handlers registered on the same path! ignoring: "+old;
Throwable t = new SolrException( 500, msg );
Throwable t = new SolrException( SolrException.ErrorCode.SERVER_ERROR, msg );
SolrConfig.severeErrors.add( t );
SolrException.logOnce(log,null,t);
}
@ -252,7 +252,7 @@ final class RequestHandlers {
_handler.init( _args );
}
catch( Exception ex ) {
throw new SolrException( 500, "lazy loading error", ex );
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "lazy loading error", ex );
}
}
return _handler;
@ -327,3 +327,4 @@ final class RequestHandlers {

View File

@ -164,7 +164,7 @@ public final class SolrCore {
} catch (SolrException e) {
throw e;
} catch (Exception e) {
throw new SolrException(500,"Error Instantiating Update Handler "+className, e);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error Instantiating Update Handler "+className, e);
}
}
@ -411,7 +411,7 @@ public final class SolrCore {
String msg="Error opening new searcher. exceeded limit of maxWarmingSearchers="+maxWarmingSearchers + ", try again later.";
log.warning(msg);
// HTTP 503==service unavailable, or 409==Conflict
throw new SolrException(503,msg,true);
throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE,msg,true);
} else if (onDeckSearchers > 1) {
log.info("PERFORMANCE WARNING: Overlapping onDeckSearchers=" + onDeckSearchers);
}
@ -668,7 +668,7 @@ public final class SolrCore {
SolrRequestHandler handler = getRequestHandler(req.getQueryType());
if (handler==null) {
log.warning("Unknown Request Handler '" + req.getQueryType() +"' :" + req);
throw new SolrException(400,"Unknown Request Handler '" + req.getQueryType() + "'", true);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Unknown Request Handler '" + req.getQueryType() + "'", true);
}
execute(handler, req, rsp);
}
@ -690,7 +690,7 @@ public final class SolrCore {
if( ep != null ) {
EchoParamStyle echoParams = EchoParamStyle.get( ep );
if( echoParams == null ) {
throw new SolrException(400,"Invalid value '" + ep + "' for " + SolrParams.HEADER_ECHO_PARAMS
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Invalid value '" + ep + "' for " + SolrParams.HEADER_ECHO_PARAMS
+ " parameter, use '" + EchoParamStyle.EXPLICIT + "' or '" + EchoParamStyle.ALL + "'" );
}
if( echoParams == EchoParamStyle.EXPLICIT ) {
@ -777,3 +777,4 @@ public final class SolrCore {
}

View File

@ -25,31 +25,80 @@ import java.io.PrintWriter;
* @author yonik
* @version $Id$
*/
public class SolrException extends RuntimeException {
/**
* @since solr 1.2
*/
public enum ErrorCode {
BAD_REQUEST( 400 ),
NOT_FOUND( 404 ),
SERVER_ERROR( 500 ),
SERVICE_UNAVAILABLE( 503 );
final int code;
private ErrorCode( int c )
{
code = c;
}
};
public boolean logged=false;
public SolrException(ErrorCode code, String msg) {
super(msg);
this.code=code.code;
}
public SolrException(ErrorCode code, String msg, boolean alreadyLogged) {
super(msg);
this.code=code.code;
this.logged=alreadyLogged;
}
public SolrException(ErrorCode code, String msg, Throwable th, boolean alreadyLogged) {
super(msg,th);
this.code=code.code;
logged=alreadyLogged;
}
public SolrException(ErrorCode code, String msg, Throwable th) {
this(code,msg,th,true);
}
public SolrException(ErrorCode code, Throwable th) {
super(th);
this.code=code.code;
logged=true;
}
@Deprecated
public SolrException(int code, String msg) {
super(msg);
this.code=code;
}
@Deprecated
public SolrException(int code, String msg, boolean alreadyLogged) {
super(msg);
this.code=code;
this.logged=alreadyLogged;
}
@Deprecated
public SolrException(int code, String msg, Throwable th, boolean alreadyLogged) {
super(msg,th);
this.code=code;
logged=alreadyLogged;
}
@Deprecated
public SolrException(int code, String msg, Throwable th) {
this(code,msg,th,true);
}
@Deprecated
public SolrException(int code, Throwable th) {
super(th);
this.code=code;
@ -87,6 +136,7 @@ public class SolrException extends RuntimeException {
// public String toString() { return toStr(this); } // oops, inf loop
@Override
public String toString() { return super.toString(); }
public static String toStr(Throwable e) {

View File

@ -47,7 +47,7 @@ public class CSVRequestHandler extends RequestHandlerBase {
Iterable<ContentStream> streams = req.getContentStreams();
if (streams == null) {
if(!RequestHandlerUtils.handleCommit(req, rsp, false)) {
throw new SolrException( 400, "missing content stream" );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "missing content stream" );
}
return;
}
@ -189,7 +189,7 @@ abstract class CSVLoader {
base.add(builder,line,column,val);
}
} catch (IOException e) {
throw new SolrException(400,"");
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"");
}
}
}
@ -220,13 +220,13 @@ abstract class CSVLoader {
strategy = new CSVStrategy(',', '"', CSVStrategy.COMMENTS_DISABLED, true, false, true);
String sep = params.get(SEPARATOR);
if (sep!=null) {
if (sep.length()!=1) throw new SolrException(400,"Invalid separator:'"+sep+"'");
if (sep.length()!=1) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Invalid separator:'"+sep+"'");
strategy.setDelimiter(sep.charAt(0));
}
String encapsulator = params.get(ENCAPSULATOR);
if (encapsulator!=null) {
if (encapsulator.length()!=1) throw new SolrException(400,"Invalid encapsulator:'"+sep+"'");
if (encapsulator.length()!=1) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Invalid encapsulator:'"+sep+"'");
strategy.setEncapsulator(encapsulator.charAt(0));
}
@ -242,7 +242,7 @@ abstract class CSVLoader {
// assume the file has the headers if they aren't supplied in the args
hasHeader=true;
} else if (hasHeader) {
throw new SolrException(400,"CSVLoader: must specify fieldnames=<fields>* or header=true");
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"CSVLoader: must specify fieldnames=<fields>* or header=true");
}
} else {
// if the fieldnames were supplied and the file has a header, we need to
@ -285,7 +285,7 @@ abstract class CSVLoader {
for (String mapRule : fmap) {
String[] mapArgs = colonSplit.split(mapRule,-1);
if (mapArgs.length!=2)
throw new SolrException(400, "Map rules must be of the form 'from:to' ,got '"+mapRule+"'");
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Map rules must be of the form 'from:to' ,got '"+mapRule+"'");
adders[i] = new CSVLoader.FieldMapperSingle(mapArgs[0], mapArgs[1], adders[i]);
}
}
@ -311,7 +311,7 @@ abstract class CSVLoader {
sb.append(errHeader+", line="+lineno + ","+msg+"\n\tvalues={");
for (String val: line) { sb.append("'"+val+"',"); }
sb.append('}');
throw new SolrException(400,sb.toString());
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,sb.toString());
}
/** load the CSV input */
@ -333,7 +333,7 @@ abstract class CSVLoader {
if (fieldnames==null) {
fieldnames = parser.getLine();
if (fieldnames==null) {
throw new SolrException(400,"Expected fieldnames in CSV input");
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Expected fieldnames in CSV input");
}
prepareFields();
}
@ -388,3 +388,4 @@ class SingleThreadedCSVLoader extends CSVLoader {
}
}

View File

@ -113,7 +113,7 @@ public class SpellCheckerRequestHandler extends RequestHandlerBase {
reopen();
rsp.add("cmdExecuted","reopen");
} else {
throw new SolrException(400, "Unrecognized Command: " + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Unrecognized Command: " + cmd);
}
}
@ -147,7 +147,7 @@ public class SpellCheckerRequestHandler extends RequestHandlerBase {
private void rebuild(SolrQueryRequest req) throws IOException, SolrException {
if (null == termSourceField) {
throw new SolrException
(500, "can't rebuild spellchecker index without termSourceField configured");
(SolrException.ErrorCode.SERVER_ERROR, "can't rebuild spellchecker index without termSourceField configured");
}
IndexReader indexReader = req.getSearcher().getReader();

View File

@ -72,7 +72,7 @@ public class XmlUpdateRequestHandler extends RequestHandlerBase
Iterable<ContentStream> streams = req.getContentStreams();
if( streams == null ) {
if( !RequestHandlerUtils.handleCommit(req, rsp, false) ) {
throw new SolrException( 400, "missing content stream" );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "missing content stream" );
}
return;
}
@ -262,7 +262,7 @@ public class XmlUpdateRequestHandler extends RequestHandlerBase
(System.currentTimeMillis()-startTime));
} else {
log.warning("unexpected XML tag /delete/"+currTag);
throw new SolrException(400,"unexpected XML tag /delete/"+currTag);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unexpected XML tag /delete/"+currTag);
}
res.add( "delete", "" );
@ -303,7 +303,7 @@ public class XmlUpdateRequestHandler extends RequestHandlerBase
if (!"field".equals(tname)) {
log.warning("unexpected XML tag doc/"+tname);
throw new SolrException(400,"unexpected XML tag doc/"+tname);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unexpected XML tag doc/"+tname);
}
//

View File

@ -105,7 +105,7 @@ public class LukeRequestHandler extends RequestHandlerBase
Term t = new Term( uniqueKey.getName(), v );
docId = searcher.getFirstMatch( t );
if( docId < 0 ) {
throw new SolrException( 404, "Can't find document: "+params.get( ID ) );
throw new SolrException( SolrException.ErrorCode.NOT_FOUND, "Can't find document: "+params.get( ID ) );
}
}
@ -117,7 +117,7 @@ public class LukeRequestHandler extends RequestHandlerBase
}
catch( Exception ex ) {}
if( doc == null ) {
throw new SolrException( 404, "Can't find document: "+docId );
throw new SolrException( SolrException.ErrorCode.NOT_FOUND, "Can't find document: "+docId );
}
SimpleOrderedMap<Object> info = getDocumentFieldsInfo( doc, docId, reader, schema );
@ -533,3 +533,4 @@ public class LukeRequestHandler extends RequestHandlerBase

View File

@ -227,7 +227,7 @@ public class DisMaxRequestHandler extends RequestHandlerBase {
altUserQuery = p.parse(altQ);
query.add( altUserQuery , Occur.MUST );
} else {
throw new SolrException( 400, "missing query string" );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "missing query string" );
}
}
else {

View File

@ -47,7 +47,7 @@ public class RequiredSolrParams extends SolrParams {
public String get(String param) {
String val = params.get(param);
if( val == null ) {
throw new SolrException( 400, "Missing required parameter: "+param );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Missing required parameter: "+param );
}
return val;
}
@ -56,7 +56,7 @@ public class RequiredSolrParams extends SolrParams {
public String[] getParams(String param) {
String[] vals = params.getParams(param);
if( vals == null || vals.length == 0 ) {
throw new SolrException( 400, "Missing required parameter: "+param );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Missing required parameter: "+param );
}
return vals;
}

View File

@ -252,7 +252,7 @@ public abstract class SolrParams {
return val==null ? null : Integer.valueOf(val);
}
catch( Exception ex ) {
throw new SolrException( 400, ex.getMessage(), ex );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
}
@ -263,7 +263,7 @@ public abstract class SolrParams {
return val==null ? def : Integer.parseInt(val);
}
catch( Exception ex ) {
throw new SolrException( 400, ex.getMessage(), ex );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
}
@ -275,7 +275,7 @@ public abstract class SolrParams {
return val==null ? null : Integer.valueOf(val);
}
catch( Exception ex ) {
throw new SolrException( 400, ex.getMessage(), ex );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
}
@ -287,7 +287,7 @@ public abstract class SolrParams {
return val==null ? def : Integer.parseInt(val);
}
catch( Exception ex ) {
throw new SolrException( 400, ex.getMessage(), ex );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
}
@ -299,7 +299,7 @@ public abstract class SolrParams {
return val==null ? null : Float.valueOf(val);
}
catch( Exception ex ) {
throw new SolrException( 400, ex.getMessage(), ex );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
}
@ -310,7 +310,7 @@ public abstract class SolrParams {
return val==null ? def : Float.parseFloat(val);
}
catch( Exception ex ) {
throw new SolrException( 400, ex.getMessage(), ex );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
}
@ -321,7 +321,7 @@ public abstract class SolrParams {
return val==null ? null : Float.valueOf(val);
}
catch( Exception ex ) {
throw new SolrException( 400, ex.getMessage(), ex );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
}
@ -333,7 +333,7 @@ public abstract class SolrParams {
return val==null ? def : Float.parseFloat(val);
}
catch( Exception ex ) {
throw new SolrException( 400, ex.getMessage(), ex );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, ex.getMessage(), ex );
}
}
@ -349,7 +349,7 @@ public abstract class SolrParams {
return false;
}
}
throw new SolrException( 400, "invalid boolean value: "+s );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "invalid boolean value: "+s );
}
/** Create a Map<String,String> from a NamedList given no keys are repeated */
@ -407,3 +407,4 @@ public abstract class SolrParams {

View File

@ -98,7 +98,7 @@ public abstract class SolrQueryRequestBase implements SolrQueryRequest {
public int getIntParam(String name) {
String s = getParam(name);
if (s==null) {
throw new SolrException(500,"Missing required parameter '"+name+"' from " + this);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Missing required parameter '"+name+"' from " + this);
}
return Integer.parseInt(s);
}
@ -119,7 +119,7 @@ public abstract class SolrQueryRequestBase implements SolrQueryRequest {
public String getStrParam(String name) {
String s = getParam(name);
if (s==null) {
throw new SolrException(500,"Missing required parameter '"+name+"' from " + this);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Missing required parameter '"+name+"' from " + this);
}
return s;
}

View File

@ -93,7 +93,7 @@ public class StandardRequestHandler extends RequestHandlerBase {
qstr = commands.get( 0 );
}
else if( commands.size() > 2 ) {
throw new SolrException( 400, "If you want to use multiple ';' in the query, use the 'sort' param." );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "If you want to use multiple ';' in the query, use the 'sort' param." );
}
}
@ -202,3 +202,4 @@ public class StandardRequestHandler extends RequestHandlerBase {

View File

@ -102,10 +102,10 @@ public class DateField extends FieldType {
try {
return toInternal(p.parseMath(val.substring(3)));
} catch (ParseException e) {
throw new SolrException(400,"Invalid Date Math String:'" +val+'\'',e);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Invalid Date Math String:'" +val+'\'',e);
}
}
throw new SolrException(400,"Invalid Date String:'" +val+'\'');
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Invalid Date String:'" +val+'\'');
}
public String toInternal(Date val) {

View File

@ -170,7 +170,7 @@ public abstract class FieldType extends FieldProperties {
try {
val = toInternal(externalVal);
} catch (NumberFormatException e) {
throw new SolrException(500, "Error while creating field '" + field + "' from value '" + externalVal + "'", e, false);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Error while creating field '" + field + "' from value '" + externalVal + "'", e, false);
}
if (val==null) return null;
if (!field.indexed() && !field.stored()) {

View File

@ -344,7 +344,7 @@ public final class IndexSchema {
String msg = "[schema.xml] Duplicate fieldType definition for '"
+ ft.typeName + "' ignoring: "+old.toString();
Throwable t = new SolrException( 500, msg );
Throwable t = new SolrException( SolrException.ErrorCode.SERVER_ERROR, msg );
SolrException.logOnce(log,null,t);
SolrConfig.severeErrors.add( t );
}
@ -370,7 +370,7 @@ public final class IndexSchema {
FieldType ft = fieldTypes.get(type);
if (ft==null) {
throw new SolrException(400,"Unknown fieldtype '" + type + "'",false);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Unknown fieldtype '" + type + "'",false);
}
Map<String,String> args = DOMUtil.toMapExcept(attrs, "name", "type");
@ -386,7 +386,7 @@ public final class IndexSchema {
String msg = "[schema.xml] Duplicate field definition for '"
+ f.getName() + "' ignoring: "+old.toString();
Throwable t = new SolrException( 500, msg );
Throwable t = new SolrException( SolrException.ErrorCode.SERVER_ERROR, msg );
SolrException.logOnce(log,null,t);
SolrConfig.severeErrors.add( t );
}
@ -408,7 +408,7 @@ public final class IndexSchema {
String msg = "[schema.xml] Duplicate DynamicField definition for '"
+ f.getName() + "' ignoring: "+f.toString();
Throwable t = new SolrException( 500, msg );
Throwable t = new SolrException( SolrException.ErrorCode.SERVER_ERROR, msg );
SolrException.logOnce(log,null,t);
SolrConfig.severeErrors.add( t );
dup = true;
@ -516,7 +516,7 @@ public final class IndexSchema {
}
}
if( df == null ) {
throw new SolrException( 500, "copyField dynamic destination must match a dynamicField." );
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "copyField dynamic destination must match a dynamicField." );
}
dCopies.add(new DynamicDestCopy(source, df ));
}
@ -526,7 +526,7 @@ public final class IndexSchema {
}
else if( destIsPattern ) {
String msg = "copyField only supports a dynamic destination if the source is also dynamic" ;
throw new SolrException( 500, msg );
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, msg );
}
else {
// retrieve the field to force an exception if it doesn't exist
@ -553,7 +553,7 @@ public final class IndexSchema {
} catch(Exception e) {
// unexpected exception...
SolrConfig.severeErrors.add( e );
throw new SolrException(500,"Schema Parsing Failed",e,false);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Schema Parsing Failed",e,false);
}
analyzer = new SolrIndexAnalyzer();
@ -588,7 +588,7 @@ public final class IndexSchema {
NodeList nList = (NodeList)xpath.evaluate("./filter", node, XPathConstants.NODESET);
if (tokNode==null){
throw new SolrException(500,"analyzer without class or tokenizer & filter list");
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"analyzer without class or tokenizer & filter list");
}
TokenizerFactory tfac = readTokenizerFactory(tokNode);
@ -598,7 +598,7 @@ public final class IndexSchema {
NodeList nList = node.getChildNodes();
TokenizerFactory tfac = readTokenizerFactory(nList.item(0));
if (tfac==null) {
throw new SolrException(500,"TokenizerFactory must be specified first in analyzer");
throw new SolrException( SolrException.StatusCode.SERVER_ERROR,"TokenizerFactory must be specified first in analyzer");
}
******/
@ -826,7 +826,7 @@ public final class IndexSchema {
/*** REMOVED -YCS
if (defaultFieldType != null) return new SchemaField(fieldName,defaultFieldType);
***/
throw new SolrException(400,"undefined field "+fieldName);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"undefined field "+fieldName);
}
/**
@ -885,7 +885,7 @@ public final class IndexSchema {
for (DynamicField df : dynamicFields) {
if (df.matches(fieldName)) return df.prototype.getType();
}
throw new SolrException(400,"undefined field "+fieldName);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"undefined field "+fieldName);
}
private FieldType dynFieldType(String fieldName) {
@ -947,3 +947,4 @@ public final class IndexSchema {

View File

@ -166,14 +166,14 @@ abstract class DocSetBase implements DocSet {
* @throws SolrException Base implementation does not allow modifications
*/
public void add(int doc) {
throw new SolrException(500,"Unsupported Operation");
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Unsupported Operation");
}
/**
* @throws SolrException Base implementation does not allow modifications
*/
public void addUnique(int doc) {
throw new SolrException(500,"Unsupported Operation");
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Unsupported Operation");
}
/**
@ -238,3 +238,4 @@ abstract class DocSetBase implements DocSet {

View File

@ -73,7 +73,7 @@ public class QueryParsing {
} catch (ParseException e) {
SolrCore.log(e);
throw new SolrException(400,"Error parsing Lucene query",e);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Error parsing Lucene query",e);
}
}
@ -101,7 +101,7 @@ public class QueryParsing {
} catch (ParseException e) {
SolrCore.log(e);
throw new SolrException(400,"Query parsing error: " + e.getMessage(),e);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Query parsing error: " + e.getMessage(),e);
}
}
@ -177,12 +177,12 @@ public class QueryParsing {
top = false;
}
else {
throw new SolrException( 400, "Unknown sort order: "+order);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Unknown sort order: "+order);
}
part = part.substring( 0, idx ).trim();
}
else {
throw new SolrException( 400, "Missing sort order." );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Missing sort order." );
}
if( "score".equals(part) ) {
@ -204,10 +204,10 @@ public class QueryParsing {
f = schema.getField(part);
}
catch( SolrException e ){
throw new SolrException( 400, "can not sort on undefined field: "+part, e );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "can not sort on undefined field: "+part, e );
}
if (f == null || !f.indexed()){
throw new SolrException( 400, "can not sort on unindexed field: "+part );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "can not sort on unindexed field: "+part );
}
lst[i] = f.getType().getSortField(f,top);
}

View File

@ -78,7 +78,7 @@ public class TestRequestHandler implements SolrRequestHandler {
// we need to un-escape them before we pass to QueryParser
try {
String sreq = req.getQueryString();
if (sreq==null) throw new SolrException(400,"Missing queryString");
if (sreq==null) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Missing queryString");
List<String> commands = StrUtils.splitSmart(sreq,';');
String qs = commands.size() >= 1 ? commands.get(0) : "";
@ -301,3 +301,4 @@ public class TestRequestHandler implements SolrRequestHandler {
}

View File

@ -109,7 +109,7 @@ public class DirectUpdateHandler extends UpdateHandler {
}
protected boolean existsInIndex(String indexedId) throws IOException {
if (idField == null) throw new SolrException(400,"Operation requires schema to have a unique key field");
if (idField == null) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Operation requires schema to have a unique key field");
closeWriter();
openSearcher();
@ -127,7 +127,7 @@ public class DirectUpdateHandler extends UpdateHandler {
protected int deleteInIndex(String indexedId) throws IOException {
if (idField == null) throw new SolrException(400,"Operation requires schema to have a unique key field");
if (idField == null) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Operation requires schema to have a unique key field");
closeWriter(); openSearcher();
IndexReader ir = searcher.getReader();
@ -173,9 +173,9 @@ public class DirectUpdateHandler extends UpdateHandler {
// could return the number of docs deleted, but is that always possible to know???
public void delete(DeleteUpdateCommand cmd) throws IOException {
if (!cmd.fromPending && !cmd.fromCommitted)
throw new SolrException(400,"meaningless command: " + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"meaningless command: " + cmd);
if (!cmd.fromPending || !cmd.fromCommitted)
throw new SolrException(400,"operation not supported" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"operation not supported" + cmd);
String indexedId = idFieldType.toInternal(cmd.id);
synchronized(this) {
deleteInIndex(indexedId);
@ -187,9 +187,9 @@ public class DirectUpdateHandler extends UpdateHandler {
// Depending on implementation, we may not be able to immediately determine num...
public void deleteByQuery(DeleteUpdateCommand cmd) throws IOException {
if (!cmd.fromPending && !cmd.fromCommitted)
throw new SolrException(400,"meaningless command: " + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"meaningless command: " + cmd);
if (!cmd.fromPending || !cmd.fromCommitted)
throw new SolrException(400,"operation not supported" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"operation not supported" + cmd);
Query q = QueryParsing.parseQuery(cmd.query, schema);
@ -221,7 +221,7 @@ public class DirectUpdateHandler extends UpdateHandler {
} catch (IOException e) {
try { closeSearcher(); } catch (Exception ee) { SolrException.log(SolrCore.log,ee); }
SolrException.log(SolrCore.log,e);
throw new SolrException(500,"Error deleting doc# "+doc,e);
throw new SolrException( SolrException.StatusCode.SERVER_ERROR,"Error deleting doc# "+doc,e);
}
}
}
@ -324,21 +324,21 @@ public class DirectUpdateHandler extends UpdateHandler {
return addConditionally(cmd);
} else if (!cmd.allowDups && cmd.overwritePending && !cmd.overwriteCommitted) {
// return overwriteBoth(cmd);
throw new SolrException(400,"unsupported param combo:" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
} else if (!cmd.allowDups && cmd.overwritePending && cmd.overwriteCommitted) {
return overwriteBoth(cmd);
} else if (cmd.allowDups && !cmd.overwritePending && !cmd.overwriteCommitted) {
return allowDups(cmd);
} else if (cmd.allowDups && !cmd.overwritePending && cmd.overwriteCommitted) {
// return overwriteBoth(cmd);
throw new SolrException(400,"unsupported param combo:" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
} else if (cmd.allowDups && cmd.overwritePending && !cmd.overwriteCommitted) {
// return overwriteBoth(cmd);
throw new SolrException(400,"unsupported param combo:" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
} else if (cmd.allowDups && cmd.overwritePending && cmd.overwriteCommitted) {
return overwriteBoth(cmd);
}
throw new SolrException(400,"unsupported param combo:" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
}
public void close() throws IOException {

View File

@ -231,27 +231,27 @@ public class DirectUpdateHandler2 extends UpdateHandler {
// protected with iwCommit (which iwAccess excludes from this block).
synchronized (this) {
if (!cmd.allowDups && !cmd.overwritePending && !cmd.overwriteCommitted) {
throw new SolrException(400,"unsupported param combo:" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
// this would need a reader to implement (to be able to check committed
// before adding.)
// return addNoOverwriteNoDups(cmd);
} else if (!cmd.allowDups && !cmd.overwritePending && cmd.overwriteCommitted) {
rc = addConditionally(cmd);
} else if (!cmd.allowDups && cmd.overwritePending && !cmd.overwriteCommitted) {
throw new SolrException(400,"unsupported param combo:" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
} else if (!cmd.allowDups && cmd.overwritePending && cmd.overwriteCommitted) {
rc = overwriteBoth(cmd);
} else if (cmd.allowDups && !cmd.overwritePending && !cmd.overwriteCommitted) {
rc = allowDups(cmd);
} else if (cmd.allowDups && !cmd.overwritePending && cmd.overwriteCommitted) {
throw new SolrException(400,"unsupported param combo:" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
} else if (cmd.allowDups && cmd.overwritePending && !cmd.overwriteCommitted) {
throw new SolrException(400,"unsupported param combo:" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
} else if (cmd.allowDups && cmd.overwritePending && cmd.overwriteCommitted) {
rc = overwriteBoth(cmd);
}
if (rc == -1)
throw new SolrException(400,"unsupported param combo:" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
if (rc == 1) {
// adding document -- prep writer
@ -290,12 +290,12 @@ public class DirectUpdateHandler2 extends UpdateHandler {
if (!cmd.fromPending && !cmd.fromCommitted) {
numErrors.incrementAndGet();
numErrorsCumulative.incrementAndGet();
throw new SolrException(400,"meaningless command: " + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"meaningless command: " + cmd);
}
if (!cmd.fromPending || !cmd.fromCommitted) {
numErrors.incrementAndGet();
numErrorsCumulative.incrementAndGet();
throw new SolrException(400,"operation not supported" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"operation not supported" + cmd);
}
iwCommit.lock();
@ -315,12 +315,12 @@ public class DirectUpdateHandler2 extends UpdateHandler {
if (!cmd.fromPending && !cmd.fromCommitted) {
numErrors.incrementAndGet();
numErrorsCumulative.incrementAndGet();
throw new SolrException(400,"meaningless command: " + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"meaningless command: " + cmd);
}
if (!cmd.fromPending || !cmd.fromCommitted) {
numErrors.incrementAndGet();
numErrorsCumulative.incrementAndGet();
throw new SolrException(400,"operation not supported" + cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"operation not supported" + cmd);
}
boolean madeIt=false;

View File

@ -59,7 +59,7 @@ public class DocumentBuilder {
if (!sfield.multiValued()) {
String oldValue = map.put(sfield.getName(), val);
if (oldValue != null) {
throw new SolrException(400,"ERROR: multiple values encountered for non multiValued field " + sfield.getName()
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"ERROR: multiple values encountered for non multiValued field " + sfield.getName()
+ ": first='" + oldValue + "' second='" + val + "'");
}
}
@ -94,7 +94,7 @@ public class DocumentBuilder {
// error if this field name doesn't match anything
if (sfield==null && (destArr==null || destArr.length==0)) {
throw new SolrException(400,"ERROR:unknown field '" + name + "'");
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"ERROR:unknown field '" + name + "'");
}
}
@ -134,7 +134,7 @@ public class DocumentBuilder {
builder.append(field);
builder.append(" ");
}
throw new SolrException(400, builder.toString());
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, builder.toString());
}
Document ret = doc; doc=null;

View File

@ -73,7 +73,7 @@ public abstract class UpdateHandler implements SolrInfoMBean {
commitCallbacks.add(listener);
log.info("added SolrEventListener for postCommit: " + listener);
} catch (Exception e) {
throw new SolrException(500,"error parsing event listevers", e, false);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"error parsing event listevers", e, false);
}
}
}
@ -88,7 +88,7 @@ public abstract class UpdateHandler implements SolrInfoMBean {
optimizeCallbacks.add(listener);
log.info("added SolarEventListener for postOptimize: " + listener);
} catch (Exception e) {
throw new SolrException(500,"error parsing event listeners", e, false);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"error parsing event listeners", e, false);
}
}
}
@ -129,15 +129,15 @@ public abstract class UpdateHandler implements SolrInfoMBean {
protected final String getIndexedId(Document doc) {
if (idField == null)
throw new SolrException(400,"Operation requires schema to have a unique key field");
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Operation requires schema to have a unique key field");
// Right now, single valued fields that require value transformation from external to internal (indexed)
// form have that transformation already performed and stored as the field value.
Fieldable[] id = doc.getFieldables( idField.getName() );
if (id == null || id.length < 1)
throw new SolrException(400,"Document is missing uniqueKey field " + idField.getName());
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Document is missing uniqueKey field " + idField.getName());
if( id.length > 1 )
throw new SolrException(400,"Document specifies multiple unique ids! " + idField.getName());
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Document specifies multiple unique ids! " + idField.getName());
return idFieldType.storedToIndexed( id[0] );
}
@ -172,7 +172,7 @@ public abstract class UpdateHandler implements SolrInfoMBean {
} catch (IOException e) {
// don't try to close the searcher on failure for now...
// try { closeSearcher(); } catch (Exception ee) { SolrException.log(log,ee); }
throw new SolrException(500,"Error deleting doc# "+doc,e,false);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error deleting doc# "+doc,e,false);
}
}
}
@ -180,3 +180,4 @@ public abstract class UpdateHandler implements SolrInfoMBean {
}

View File

@ -296,7 +296,7 @@ public class DOMUtil {
}
fragment = System.getProperty(propertyName,defaultValue);
if (fragment == null) {
throw new SolrException(500, "No system property or default value specified for " + propertyName);
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "No system property or default value specified for " + propertyName);
}
}
sb.append(fragment);

View File

@ -96,7 +96,7 @@ public class DirectSolrConnection
System.setProperty("java.util.logging.config.file", loggingConfig.getAbsolutePath() );
}
else {
throw new SolrException( 500, "can not find logging file: "+loggingConfig );
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "can not find logging file: "+loggingConfig );
}
}
@ -105,7 +105,7 @@ public class DirectSolrConnection
if( Config.isInstanceDirInitialized() ) {
String dir = Config.getInstanceDir();
if( !dir.equals( instanceDir ) ) {
throw new SolrException( 500, "already initalized: "+dir );
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "already initalized: "+dir );
}
}
Config.setInstanceDir( instanceDir );
@ -150,12 +150,12 @@ public class DirectSolrConnection
String qt = params.get( SolrParams.QT );
handler = core.getRequestHandler( qt );
if( handler == null ) {
throw new SolrException( 400, "unknown handler: "+qt);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt);
}
}
}
if( handler == null ) {
throw new SolrException( 400, "unknown handler: "+path );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+path );
}
// Make a stream for the 'body' content

View File

@ -143,11 +143,11 @@ public class SolrDispatchFilter implements Filter
solrReq = parsers.parse( path, req );
String qt = solrReq.getParams().get( SolrParams.QT );
if( qt != null && qt.startsWith( "/" ) ) {
throw new SolrException( 400, "Invalid query type. Do not use /select to access: "+qt);
new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Invalid query type. Do not use /select to access: "+qt);
}
handler = core.getRequestHandler( qt );
if( handler == null ) {
throw new SolrException( 400, "unknown handler: "+qt);
new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt);
}
}
}

View File

@ -117,7 +117,7 @@ public class SolrRequestParsers
String[] strs = params.getParams( SolrParams.STREAM_URL );
if( strs != null ) {
if( !enableRemoteStreams ) {
throw new SolrException( 400, "Remote Streaming is disabled." );
new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Remote Streaming is disabled." );
}
for( final String url : strs ) {
ContentStreamBase stream = new ContentStreamBase.URLStream( new URL(url) );
@ -132,7 +132,7 @@ public class SolrRequestParsers
strs = params.getParams( SolrParams.STREAM_FILE );
if( strs != null ) {
if( !enableRemoteStreams ) {
throw new SolrException( 400, "Remote Streaming is disabled." );
new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Remote Streaming is disabled." );
}
for( final String file : strs ) {
ContentStreamBase stream = new ContentStreamBase.FileStream( new File(file) );
@ -185,7 +185,7 @@ public class SolrRequestParsers
}
}
catch( UnsupportedEncodingException uex ) {
throw new SolrException( 500, uex );
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, uex );
}
}
return new MultiMapSolrParams( map );
@ -303,7 +303,7 @@ class MultipartRequestParser implements SolrRequestParser
final HttpServletRequest req, ArrayList<ContentStream> streams ) throws Exception
{
if( !ServletFileUpload.isMultipartContent(req) ) {
throw new SolrException( 400, "Not multipart content! "+req.getContentType() );
new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Not multipart content! "+req.getContentType() );
}
MultiMapSolrParams params = SolrRequestParsers.parseQueryString( req.getQueryString() );
@ -378,7 +378,7 @@ class StandardRequestParser implements SolrRequestParser
}
return raw.parseParamsAndFillStreams(req, streams);
}
throw new SolrException( 400, "Unsuported method: "+method );
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Unsuported method: "+method );
}
}
@ -389,3 +389,4 @@ class StandardRequestParser implements SolrRequestParser

View File

@ -61,7 +61,7 @@ public class SolrServlet extends HttpServlet {
SolrRequestHandler handler = core.getRequestHandler(solrReq.getQueryType());
if (handler==null) {
log.warning("Unknown Request Handler '" + solrReq.getQueryType() +"' :" + solrReq);
throw new SolrException(400,"Unknown Request Handler '" + solrReq.getQueryType() + "'", true);
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,"Unknown Request Handler '" + solrReq.getQueryType() + "'", true);
}
core.execute(handler, solrReq, solrRsp );
if (solrRsp.getException() == null) {